blob: 59892ac5f555ded359c763103acc1076e64c28f2 [file] [log] [blame]
/*****************************************************************************
* Copyright (c) 2016 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
*****************************************************************************/
import org.eclipse.papyrus.interoperability.rpy.blackboxes.ConstantsBlackboxes;
import org.eclipse.papyrus.interoperability.rpy.blackboxes.Rpy2PapyrusNotationBlackboxes;
modeltype umlrpy "strict" uses 'http://www.eclipse.org/Papyrus/UMLRpy/1.0.0';
modeltype ecore "strict" uses 'http://www.eclipse.org/emf/2002/Ecore';
/**
* This file provides useful method for Rpy elements
*/
library RpyUtils;
// here, this is method to help to find diagram kind
/**
* Return true if the Rpy IDiagram is a CGIClassChart
*/
query rpymetamodel::IDiagram::isRpyClassChart():Boolean{
return self.graphicChart![GraphicChartType].oclIsTypeOf(CGIClassChart);
}
/**
* Return true if the IDiagram represents a UML Class Diagram without applied stereotypes
*/
query rpymetamodel::IDiagram::isUMLPureClassDiagram():Boolean{
return self.isRpyClassChart() and self.Stereotypes->isEmpty();
}
/**
* Return true if the IDiagram is a CGIStateChart
*/
query rpymetamodel::IDiagram::isRpyStateChart():Boolean{
return self.graphicChart![GraphicChartType].oclIsTypeOf(CGIStateChart);
}
/**
* Return true if the IDiagram represents a UML State Machine Diagram without applied stereotypes
*/
query rpymetamodel::IDiagram::isUMLPureStateMachineDiagram():Boolean{
return self.isRpyStateChart() and self.Stereotypes->isEmpty();
}
//here, this is the method to know if the elements comes from the user model or from a Rpy Tool file
/**
*
* This query returns true if the diagram is a User diagram
*/
query rpymetamodel::IDiagram::isUserModelDiagram():Boolean{
//never write the next code, because if the user rename the default Package, it didn't work yet
// var res:EResource:= self.getResource();
// return res.toString().endsWith("Default.umlrpy'");
return not (
self.isRpyPredefinedC_LibraryDiagram() or
self.isRpyPredefinedCPP_LibraryDiagram() or
self.isRpySysMLLibraryDiagram() or
self.isRpyPredefinedTypeLibraryDiagram()
// or
// self.isRpyMarteLibraryDiagram()
);
}
/**
* Return true if the diagram comes from the Rpy C library
*/
helper umlrpy::IDiagram::isRpyPredefinedC_LibraryDiagram():Boolean {
return self.oclAsType(EModelElement).isComingFromRpy_PredefinedTypesC_Library();
}
/**
* Return true if the diagram comes from the Rpy CPP library
*/
helper umlrpy::IDiagram::isRpyPredefinedCPP_LibraryDiagram():Boolean {
return self.oclAsType(EModelElement).isComingFromRpy_PredefinedTypesCpp_Library();
}
/**
* Return true if the diagram comes from the Rpy SysML library
*/
helper umlrpy::IDiagram::isRpySysMLLibraryDiagram():Boolean {
return self.oclAsType(EModelElement).isComingFromRpy_SysML_Profile();
}
/**
* Return true if the diagram comes from the Rpy Predefined Type library
*/
helper umlrpy::IDiagram::isRpyPredefinedTypeLibraryDiagram():Boolean {
return self.oclAsType(EModelElement).isComingFromRpy_PredefinedTypesC_Library();
}
///**
//* Return true if the diagram comes from the Rpy Marte library
//*/
//helper umlrpy::IDiagram::isRpyMarteLibraryDiagram():Boolean {
// var resourceName:String:=self[EObject].eResource()![EResource].toString();
//// return resourceName.endsWith("MARTE.umlrpy'");
//return false;
//}
/**
* Returns true if the type come from a Rpy Library
*/
helper umlrpy::IType::isRpyLibraryType():Boolean{
return self.oclAsType(ecore::EModelElement).isComingFromARpyLibraryResource();
}
/**
* Returns true if the eobject come from a Rpy Library
*/
helper ecore::EObject::isRpyLibraryType():Boolean{
return self.oclAsType(ecore::EModelElement).isComingFromARpyLibraryResource();
}
/**
* Returns true if the eobject come from a Rpy Library
*/
helper ecore::EModelElement::isComingFromARpyLibraryResource():Boolean{
var eannotation:ecore::EAnnotation:=self.getEAnnotation(getEAnnotationFileNameSourceKey());
if(eannotation<>null){
var key1:EStringToStringMapEntry:=eannotation.details->select(a|a.key= getEAnnotationFileNameDetailKey())![EStringToStringMapEntry];
return not eannotation.details->any(key=getEAnnotationFileNameDetailKey()).value.oclIsUndefined();
};
return false;
}
/**
* Return true if the type is a Rpy C type
*/
helper umlrpy::IType::isRpyPredefinedC_Type():Boolean {
return self.oclAsType(EModelElement).isComingFromRpy_PredefinedTypesC_Library();
}
/**
* Return true if the type is a Rpy C++ type
*/
helper umlrpy::IType::isRpyPredefinedCPP_Type():Boolean {
return self.oclAsType(EModelElement).isComingFromRpy_PredefinedTypesCpp_Library();
}
/**
* Return true if the type is a Rpy SysML type
*/
helper umlrpy::IType::isRpySysMLType():Boolean {
return self.oclAsType(EModelElement).isComingFromRpy_SysML_Profile();
}
/**
* Return true if the type is a Rpy Predefined Type
*/
helper umlrpy::IType::isRpyPredefinedType():Boolean {
return self.oclAsType(EModelElement).isComingFromRpy_PredefinedTypes_Library();
}
helper ecore::EModelElement::isComingFromRpy_PredefinedTypes_Library():Boolean{
return self.isComingFromExpectedRpyFile("PredefinedTypes.sbs"); //TODO move in a const file
}
helper ecore::EModelElement::isComingFromRpy_PredefinedTypesC_Library():Boolean{
return self.isComingFromExpectedRpyFile("PredefinedTypesC.sbs"); //TODO move in a const file
}
helper ecore::EModelElement::isComingFromRpy_PredefinedTypesCpp_Library():Boolean{
return self.isComingFromExpectedRpyFile("PredefinedTypesC++.sbs"); //TODO move in a const file //TODO : check it work with c++
}
helper ecore::EModelElement::isComingFromRpy_SysML_Profile():Boolean{
return false;
}
/**
* Return true if the object comes from the file defined as argument of the method
*/
helper ecore::EModelElement::isComingFromExpectedRpyFile(filename:String):Boolean{
return self.getFileName()=filename;
}
/**
* Returns the resource of the Rpy element
*/
query rpymetamodel::IModelElement::getResource():EResource{//TODO : probably useless now
return self![EObject].eResource()![EResource];
}
/**
* Returns the width for the element
*/
query umlrpy::CGIDiagramFrame::get_Width():Integer{
var mpolygon:List(String):= self![CGIDiagramFrame].m_polygon->asList();
var mtransform:List(String):= self![CGIDiagramFrame].m_transform->asList();
return getWidth(mpolygon,mtransform);
}
/**
* Returns the heigth for the element
*/
query umlrpy::CGIDiagramFrame::get_Height():Integer{
var mpolygon:List(String):= self![CGIDiagramFrame].m_polygon->asList();
var mtransform:List(String):= self![CGIDiagramFrame].m_transform->asList();
return getHeight(mpolygon,mtransform);
}
/**
* returns the X position
*/
query umlrpy::CGIDiagramFrame::get_X_Position():Integer{
return self![CGIDiagramFrame].m_transform->at(5).get_int_from_String();
}
/**
* returns the Y position
*/
query umlrpy::CGIDiagramFrame::get_Y_Position():Integer{
return self![CGIDiagramFrame].m_transform->at(6).get_int_from_String();
}
//TODO : we should check inheritance in a test of isStereotypedBy!
/**
* Returns true if the diagram is stereotyped by a stereotype with the name stereotypeName
*/
query rpymetamodel::IDiagram::isStereotypedWith(stereotypeName:String):Boolean{
return self.Stereotypes->selectByKind(IStereotype)->select( ste | ste.name=stereotypeName)->one(true);
}
/**
* Returns true if the IClass is stereotyped by a stereotype with the name stereotypeName
*/
query rpymetamodel::IClass::isStereotypedWith(stereotypeName:String):Boolean{
self.Stereotypes->selectByType(IStereotype)->forEach(ste){
if(ste.name=stereotypeName){
return true;
};
//probably useless, because we doesn't yet have access to the real rpy library, so we can't know the supertype of the rpy stereotype
if(ste.getAllSuperStereotype()->select(s | s.name=stereotypeName)->one(true)){
return true;
}
};
return false;
}
/**
* Returns true if the IPart is stereotyped by a stereotype with the name stereotypeName
*/
query rpymetamodel::IPart::isStereotypedWith(stereotypeName:String):Boolean{
return self.Stereotypes->selectByKind(IStereotype)->select( ste | ste.name=stereotypeName)->one(true);
}
/**
* Returns true if the IType is stereotyped by a stereotype with the name stereotypeName
*/
query rpymetamodel::IType::isStereotypedWith(stereotypeName:String):Boolean{
return self.Stereotypes->selectByKind(IStereotype)->select( ste | ste.name=stereotypeName)->one(true);
}
/**
* Returns true if the IType is stereotyped by a stereotype with the name stereotypeName
*/
query rpymetamodel::IObjectLink::isStereotypedWith(stereotypeName:String):Boolean{
return self.Stereotypes->selectByKind(IStereotype)->select( ste | ste.name=stereotypeName)->one(true);
}
/**
* Convert a string to int
*/
query String::get_int_from_String():Integer{
var intValue:Integer;
if (self.asInteger().oclIsUndefined() or self.asInteger().oclIsInvalid()){
intValue:=self.asFloat().round();
}else{
intValue:=self.asInteger();
};
return intValue;
}
/**
*
* Returns all super stereotypes of itself without itself
*/
query rpymetamodel::IStereotype::getAllSuperStereotype():Set(IStereotype){
var res:Set(IStereotype);
self.Inheritances->forEach(i){
if(i.dependsOn.oclIsTypeOf(IStereotype)){
var ste:IStereotype:=i.dependsOn.oclAsType(IStereotype);
res+=ste;
res+=ste.getAllSuperStereotype();
}
};
return res;
}
/**
*
* Return true if the IClass is a Rpy Interface
*/
query rpymetamodel::IClass::isInterface():Boolean{
return self.isStereotypedWith("Interface") or self.isStereotypedWith("flowSpecification");
}
/**
*
* return true if the IRelation is a Rpy SysML Port (WARNING ISysMLPort comes from the Rpy metamodel, not from a Rpy profile!),
* so this place is here and not in the SysML qvto file!
*/
query umlrpy::IRelation::isRpyPort(): Boolean{
return self.oclIsTypeOf(umlrpy::ISysMLPort);
}
/**
* Return true if the ISysMLPort is conjugated
*/
helper umlrpy::ISysMLPort::isConjugated(): Boolean{
if(self.reversed="1"){
return true;
};
return false;
}
/**
*
* Return true if the ISysML port is stereotyped by a stereoptype named stereotypeName
*/
query umlrpy::ISysMLPort::isStereotypedWith(stereotypeName:String):Boolean{
self.Stereotypes->selectByType(IStereotype)->forEach(ste){
if(ste.name=stereotypeName){
return true;
};
if(ste.getAllSuperStereotype()->select(s | s.name=stereotypeName)->one(true)){
return true;
}
};
return false;
}
/**
* Return the name of the file stored in an EAnnotation, when available
*/
query ecore::EModelElement::getFileName():String{
var eannotation:ecore::EAnnotation:=self.getEAnnotation(getEAnnotationFileNameSourceKey());
if(eannotation<>null){
var key1:EStringToStringMapEntry:=eannotation.details->select(a|a.key= getEAnnotationFileNameDetailKey())![EStringToStringMapEntry];
return eannotation.details->any(key=getEAnnotationFileNameDetailKey()).value;
};
return "";
}
/**
* Return the name of the file stored in an EAnnotation, when available, without its extension
*/
query ecore::EModelElement::getFileNameWithoutExtension():String{
var fileName:String:=self.getFileName();
return fileName.substring(1,fileName.lastIndexOf(".")-1);
}