model.diagramType.1=ClassDiagram
model.diagramType.2=UseCaseDiagram
model.diagramType.3=SequenceDiagram
model.diagramType.4=SequenceDiagram
model.diagramType.4.viewType=collaborationView
model.diagramType.5=StateDiagram
model.diagramType.6=ActivityDiagram
model.diagramType.7=BusinessProcessDiagram
model.diagramType.8=ComponentDiagram
model.diagramType.9=DeploymentDiagram


#========================
# Note Link
#========================
model.constraint.link.NoteLink.both.1 = hasPropertyValue( %src%, "$shapeType", "Note" ) ||
\                                       hasPropertyValue( %dst%, "$shapeType", "Note" )
model.constraint.link.NoteLink.both.1.message = "Link should be drawn from Note or to Note"
model.constraint.link.NoteLink.both.2 = hasPropertyValue( %src%, "$shapeType", "Note" ) &&
\                                       !hasPropertyValue( %dst%, "$shapeType", "Note" ) ||
\                                       !hasPropertyValue( %src%, "$shapeType", "Note" ) &&
\                                       hasPropertyValue( %dst%, "$shapeType", "Note" )
model.constraint.link.NoteLink.both.2.message = "Link can't be drawn between Notes"

#========================
# Prohibited containers
#========================
model.constraint.node.*.container.1 = !hasPropertyValue( "$shapeType", "Note" ) &&
\                                     !hasPropertyValue( "$shapeType", "Actor" ) &&
\                                     !hasPropertyValue( "$shapeType", "BusinessWorker" ) &&
\                                     !hasPropertyValue( "$shapeType", "BusinessEntity" ) &&
\                                     !hasPropertyValue( "$shapeType", "StartState" ) &&
\                                     !hasPropertyValue( "$shapeType", "EndState" ) &&
\                                     !hasPropertyValue( "$shapeType", "History" ) &&
\                                     !hasPropertyValue( "$shapeType", "SyncBar" ) &&
\                                     !hasPropertyValue( "$shapeType", "Decision" ) &&
\                                     !hasPropertyValue( "$shapeType", "SignalReceipt" ) &&
\                                     !hasPropertyValue( "$shapeType", "SignalSending" ) &&
\                                     !hasPropertyValue( "$shapeType", "Interface" )
model.constraint.node.*.container.1.message = "This element can't contain other elements"
#\                                     !hasPropertyValue( "$shapeType", "Activation" ) &&


#========================
# Prohibited nestings
#========================
model.constraint.node.Note.container.1 = isPackage() || hasPropertyValue( "$shapeType", "State" ) ||
\                                                       hasPropertyValue( "$shapeType", "SwimLane" ) ||
\                                                       hasPropertyValue( "$shapeType", "SystemBoundary" )
model.constraint.node.Note.container.1.message = "Note can be inserted in State, SwimLane or SystemBoundary"
model.constraint.node.UseCase.container.1 = isPackage() || hasPropertyValue( "$shapeType", "SystemBoundary" )
model.constraint.node.UseCase.container.1.message = "UseCase can be inserted only in a System Boundary"
model.constraint.node.SystemBoundary.container.1 = isPackage()
model.constraint.node.SystemBoundary.container.1.message = "System Boundary can't be inserted in other elements"
model.constraint.node.SwimLane.container.1 = isPackage()
model.constraint.node.SwimLane.container.1.message = "Swim Lane can't be inserted in other elements"
model.constraint.node.Actor.container.1 = isPackage()
model.constraint.node.Actor.container.1.message = "Actor can't be inserted in other elements"
model.constraint.node.Object.container.1 = !hasPropertyValue( "$shapeType", "Object" ) &&
\                                          !hasPropertyValue( "$shapeType", "Activity" ) &&
\                                          !hasPropertyValue( "$shapeType", "Activation" ) &&
\                                          !hasPropertyValue( "$shapeType", "StatementBlock" ) &&
\                                          !hasPropertyValue( "$shapeType", "UseCase" )
model.constraint.node.Object.container.1.message = "Object can't be inserted in this element"
model.constraint.node.ExtensionPoint.container.1 = hasPropertyValue( "$shapeType", "UseCase" )
model.constraint.node.ExtensionPoint.container.1.message = "Extension Point make sense only for UseCase"

#========================
# Class diagram
#========================
model.constraint.link.AssociationLink.source.1 = !(hasPropertyValue("$shapeType", null) || hasPropertyValue( "$shapeType", "ClassDiagram" )) &&
\                                                !hasPropertyValue( "$shapeType", "Object" ) &&
\                                                !hasPropertyValue( "$shapeType", "Note" )
model.constraint.link.AssociationLink.source.1.message = "Association can't be drawn from Package, Object or Note"
model.constraint.link.AssociationLink.destination.1 = !hasPropertyValue( "$shapeType", "ClassDiagram" ) &&
\                                                     !hasPropertyValue( "$shapeType", "Object" ) &&
\                                                     !hasPropertyValue( "$shapeType", "Note" )
model.constraint.link.AssociationLink.destination.1.message = "Association can't be drawn to Package, Object or Note"

##

model.constraint.link.AssociatesLink.source.1 = !(hasPropertyValue( "$shapeType", null ) || hasPropertyValue("$shapeType", "ClassDiagram"))
#&&
#\                                                !hasPropertyValue( "$shapeType", "Object" ) &&
#\                                                !hasPropertyValue( "$shapeType", "Note" )
model.constraint.link.AssociatesLink.source.1.message = "Association can't be drawn from Package"
model.constraint.link.AssociatesLink.destination.1 = !hasPropertyValue( "$shapeType", "ClassDiagram" )
#&&
#\                                                     !hasPropertyValue( "$shapeType", "Object" ) &&
#\                                                     !hasPropertyValue( "$shapeType", "Note" )
model.constraint.link.AssociatesLink.destination.1.message = "Association can't be drawn to Package"

#========================
# Sequence/Collaboration diagram
#========================
model.constraint.link.MessageLink.source.1 = hasPropertyValue("$shapeType","Object") ||
\                                            hasPropertyValue("$shapeType","Activation") ||
\                                            hasPropertyValue("$shapeType","StatementBlock")
model.constraint.link.MessageLink.source.1.message = "Message can be drawn from Object, Activation or Statement block"
model.constraint.link.MessageLink.destination.1 = hasPropertyValue("$shapeType","Object") ||
\                                                 hasPropertyValue("$shapeType","Activation") ||
\                                                 hasPropertyValue("$shapeType","StatementBlock")
model.constraint.link.MessageLink.destination.1.message = "Message can be drawn to Object, Activation or Statement block"
model.constraint.link.MessageLink.both.1 = %src%->getContainingPackage() == %dst%->getContainingPackage()
model.constraint.link.MessageLink.both.1.message = "Message can't be created between elements from different packages"
model.constraint.link.CollaborationLink.source.1 = hasPropertyValue("$shapeType","Object")
model.constraint.link.CollaborationLink.source.1.message = "Collaboration link can be drawn from Object"
model.constraint.link.CollaborationLink.destination.1 = hasPropertyValue("$shapeType","Object")
model.constraint.link.CollaborationLink.destination.1.message = "Collaboration link can be drawn to Object"

model.constraint.node.Activation.container.1 = hasPropertyValue( "$shapeType", "Object" ) ||
\                                              hasPropertyValue( "$shapeType", "Activation" ) ||
\                                              hasPropertyValue( "$shapeType", "StatementBlock" )
model.constraint.node.Activation.container.1.message = "Activation can be dropped on Object, Statement block or another Activation"
model.constraint.node.StatementBlock.container.1 = isPackage() ||
\                                                  hasPropertyValue( "$shapeType", "Object" ) ||
\                                                  hasPropertyValue( "$shapeType", "Activation" ) ||
\                                                  hasPropertyValue( "$shapeType", "StatementBlock" )
model.constraint.node.StatementBlock.container.1.message = "Statement block can be dropped on Activation or another Statement block"


#========================
# State diagram
#========================
model.constraint.node.State.container.1 = isPackage() || hasPropertyValue("$shapeType","State") ||
\                                                        hasPropertyValue("$shapeType","SwimLane")
model.constraint.node.State.container.1.message = "State can be inserted in State or SwimLane"
model.constraint.node.StartState.container.1 = isPackage() || hasPropertyValue("$shapeType","State") ||
\                                                        hasPropertyValue("$shapeType","SwimLane")
model.constraint.node.StartState.container.1.message = "Start State can be inserted in State or SwimLane"
model.constraint.node.EndState.container.1 = isPackage() || hasPropertyValue("$shapeType","State") ||
\                                                        hasPropertyValue("$shapeType","SwimLane")
model.constraint.node.EndState.container.1.message = "End State can be inserted in State or SwimLane"
model.constraint.node.History.container.1 = hasPropertyValue("$shapeType","State")
model.constraint.node.History.container.1.message = "History State should be inserted in State"
model.constraint.node.SyncBar.container.1 = isPackage() || hasPropertyValue("$shapeType","State") ||
\                                                        hasPropertyValue("$shapeType","SwimLane")
model.constraint.node.SyncBar.container.1.message = "SyncBar can be inserted in State or SwimLane"


#========================
# Activity diagram
#========================
model.constraint.node.InternalTransition.container.1 = hasPropertyValue( "$shapeType", "State" ) ||
\                                                      hasPropertyValue( "$shapeType", "Activity" )
model.constraint.node.InternalTransition.container.1.message = "Internal Transition can be inserted in State or Activity"
model.constraint.node.DeferredEvent.container.1 = hasPropertyValue( "$shapeType", "State" ) ||
\                                                 hasPropertyValue( "$shapeType", "Activity" )
model.constraint.node.DeferredEvent.container.1.message = "Deferred Event can be inserted in State or Activity"
model.constraint.node.Decision.container.1      = isPackage() || hasPropertyValue( "$shapeType", "State" ) ||
\                                                 hasPropertyValue( "$shapeType", "SwimLane" )
model.constraint.node.Decision.container.1.message = "Decision can be inserted in State or SwimLane"
model.constraint.node.SignalReceipt.container.1 = isPackage() || hasPropertyValue( "$shapeType", "State" ) ||
\                                                 hasPropertyValue( "$shapeType", "SwimLane" )
model.constraint.node.SignalReceipt.container.1.message = "Signal Receipt can be inserted in State or SwimLane"
model.constraint.node.SignalSending.container.1 = isPackage() || hasPropertyValue( "$shapeType", "State" ) ||
\                                                 hasPropertyValue( "$shapeType", "SwimLane" )
model.constraint.node.SignalSending.container.1.message = "Signal Sending can be inserted in State or SwimLane"
model.constraint.node.Activity.container.1      = isPackage() || hasPropertyValue( "$shapeType", "State" ) ||
\                                                 hasPropertyValue( "$shapeType", "SwimLane" )
model.constraint.node.Activity.container.1.message = "Activity can be inserted in State or SwimLane"


model.constraint.link.TransitionLink.source.1 = hasPropertyValue("$shapeType","State") ||
\                                               hasPropertyValue("$shapeType","StartState") ||
\                                               hasPropertyValue("$shapeType","History") ||
\                                               hasPropertyValue("$shapeType","SyncBar") ||
\                                               hasPropertyValue( "$shapeType", "Activity" ) ||
\                                               hasPropertyValue( "$shapeType", "Decision" ) ||
\                                               hasPropertyValue( "$shapeType", "SignalReceipt" ) ||
\                                               hasPropertyValue( "$shapeType", "SignalSending" )
model.constraint.link.TransitionLink.source.1.message = "Transition can be drawn from any State/Activity diagram element except End state, Swim lane and Object"
model.constraint.link.TransitionLink.destination.1 = hasPropertyValue("$shapeType","State") ||
\                                               hasPropertyValue("$shapeType","EndState") ||
\                                               hasPropertyValue("$shapeType","History") ||
\                                               hasPropertyValue("$shapeType","SyncBar") ||
\                                               hasPropertyValue( "$shapeType", "Activity" ) ||
\                                               hasPropertyValue( "$shapeType", "Decision" ) ||
\                                               hasPropertyValue( "$shapeType", "SignalReceipt" ) ||
\                                               hasPropertyValue( "$shapeType", "SignalSending" )
model.constraint.link.TransitionLink.destination.1.message = "Transition can be drawn to any State/Activity diagram element except Start state, Swim lane and Object"

model.constraint.link.ObjectFlowLink.source.1 = hasPropertyValue("$shapeType","Object") ||
\                                               hasPropertyValue("$shapeType","SyncBar") ||
\                                               hasPropertyValue( "$shapeType", "Activity" ) ||
\                                               hasPropertyValue( "$shapeType", "SignalSending" )
model.constraint.link.ObjectFlowLink.source.1.message = "Object Flow source can be Object, SyncBar, Activity or SignalSending"
model.constraint.link.ObjectFlowLink.destination.1 = hasPropertyValue("$shapeType","Object") ||
\                                               hasPropertyValue("$shapeType","SyncBar") ||
\                                               hasPropertyValue( "$shapeType", "Activity" ) ||
\                                               hasPropertyValue( "$shapeType", "SignalReceipt" )
model.constraint.link.ObjectFlowLink.destination.1.message = "Object Flow destination can be Object, SyncBar, Activity or SignalReceipt"
model.constraint.link.ObjectFlowLink.both.1 = ( hasPropertyValue( %src%, "$shapeType","Object") ||
\                                               hasPropertyValue( %dst%, "$shapeType", "Object" ) ) &&
\                                             getProperty( %src%, "$shapeType" ) !=
\                                             getProperty( %dst%, "$shapeType" )
model.constraint.link.ObjectFlowLink.both.1.message = "Object Flow can't be drawn between Objects"


#========================
# Deployment diagram
#========================
model.constraint.node.Node.container.1 = isPackage() || hasPropertyValue("$shapeType","Node")
model.constraint.node.Node.container.1.message = "Node can be inserted in other Node"
model.constraint.node.Component.container.1 = !hasPropertyValue( "$shapeType", "Object" )
model.constraint.node.Component.container.1.message = "Component can't be inserted in Object"
model.constraint.node.Interface.container.1 = !hasPropertyValue( "$shapeType", "Object" )
model.constraint.node.Interface.container.1.message = "Interface can't be inserted in Object"

model.constraint.link.SupportsLink.source.1 = hasPropertyValue("$shapeType", "Component") ||
\                                             hasPropertyValue("$shapeType", "Interface" ) ||
\                                             hasProperty( "$interface" )
model.constraint.link.SupportsLink.source.1.message = "Supports association can be drawn from Component or Interface"
model.constraint.link.SupportsLink.destination.1 = hasPropertyValue("$shapeType", "Component") ||
\                                             hasPropertyValue("$shapeType", "Interface" ) ||
\                                             hasProperty( "$interface" )
model.constraint.link.SupportsLink.destination.1.message = "Supports association can be drawn to Component or Interface"


#========================
# Business Process diagram
#========================
model.constraint.node.BusinessWorker.container.1 = isPackage() || hasPropertyValue( "$shapeType", "SystemBoundary" )
model.constraint.node.BusinessWorker.container.1.message = "BusinessWorker can be inserted only in a System Boundary"
model.constraint.node.BusinessEntity.container.1 = isPackage() || hasPropertyValue( "$shapeType", "SystemBoundary" )
model.constraint.node.BusinessEntity.container.1.message = "BusinessEntity can be inserted only in a System Boundary"

model.constraint.link.CommunicatesLink.source.1 = hasPropertyValue( "$shapeType", "BusinessWorker" ) ||
\                                                 hasPropertyValue( "$shapeType", "BusinessEntity" ) ||
\                                                 hasPropertyValue( "$shapeType", "Actor" ) ||
\                                                 hasPropertyValue( "$shapeType", "UseCase" ) ||
\                                                 hasPropertyValue( "$shapeType", "UseCaseDiagram" )
model.constraint.link.CommunicatesLink.source.1.message = "Communicates association can be drawn from UseCase, Actor, Worker, Entity or UseCase package"
model.constraint.link.CommunicatesLink.destination.1 = hasPropertyValue( "$shapeType", "BusinessWorker" ) ||
\                                                      hasPropertyValue( "$shapeType", "BusinessEntity" ) ||
\                                                      hasPropertyValue( "$shapeType", "Actor" ) ||
\                                                      hasPropertyValue( "$shapeType", "UseCase" ) ||
\                                                      hasPropertyValue( "$shapeType", "UseCaseDiagram" )
model.constraint.link.CommunicatesLink.destination.1.message = "Communicates association can be drawn to UseCase, Actor, Worker, Entity or UseCase package"
model.constraint.link.CommunicatesLink.both.1 = !hasPropertyValue( %src%, "$shapeType", "UseCase" ) ||
\                                               !hasPropertyValue( %dst%, "$shapeType", "UseCase" )
model.constraint.link.CommunicatesLink.both.1.message = "Communicates association can't be drawn between UseCases"
model.constraint.link.CommunicatesLink.both.2 = !hasPropertyValue( %src%, "$shapeType", "Actor" ) ||
\                                               !hasPropertyValue( %dst%, "$shapeType", "Actor" )
model.constraint.link.CommunicatesLink.both.2.message = "Communicates association can't be drawn between Actors"
model.constraint.link.CommunicatesLink.both.3 = hasPropertyValue( %src%, "$shapeType", "BusinessEntity" ) ||
\                                               hasPropertyValue( %src%, "$shapeType", "BusinessWorker" ) ||
\                                               !hasPropertyValue( %dst%, "$shapeType", "BusinessEntity")
model.constraint.link.CommunicatesLink.both.3.message = "Communicates association to Entity can be drawn from Worker or Entity"

model.constraint.link.CommunicatesLink.both.4 = hasPropertyValue( %dst%, "$shapeType", "BusinessEntity" ) ||
\                                               hasPropertyValue( %dst%, "$shapeType", "BusinessWorker" ) ||
\                                               !hasPropertyValue( %src%, "$shapeType", "BusinessEntity")
model.constraint.link.CommunicatesLink.both.4.message = "Communicates association can be drawn from Entity to Worker or Entity"
model.constraint.link.AggregatesLink.source.1 = hasPropertyValue( "$shapeType", "BusinessEntity" ) ||
\                                               hasPropertyValue( "$shapeType", "BusinessWorker" ) ||
\                                               hasPropertyValue( "$shapeType", "Object" ) ||
\                                               hasPropertyValue( "$shapeType", "Node" ) ||
\                                               hasPropertyValue( "$shapeType", "Component" )
model.constraint.link.AggregatesLink.source.1.message = "Aggregates association can be drawn from Object, BusinessWorker, BusinessEntity, Node or Component"
model.constraint.link.AggregatesLink.destination.1 = hasPropertyValue( "$shapeType", "BusinessEntity" ) ||
\                                                    hasPropertyValue( "$shapeType", "BusinessWorker" ) ||
\                                                    hasPropertyValue( "$shapeType", "Object" ) ||
\                                                    hasPropertyValue( "$shapeType", "Node" ) ||
\                                                    hasPropertyValue( "$shapeType", "Component" )
model.constraint.link.AggregatesLink.destination.1.message = "Aggregates association can be drawn to Object, BusinessWorker, BusinessEntity, Node or Component"
model.constraint.link.AggregatesLink.both.1 = ( getProperty( %src%, "$shapeType" ) ==
\                                               getProperty( %dst%, "$shapeType" )
\                                             ) ||
\                                             ( hasPropertyValue( %src%, "$shapeType", "Node" ) &&
\                                               ( hasPropertyValue( %dst%, "$shapeType", "Component" ) ||
\                                                 hasPropertyValue( %dst%, "$shapeType", "Object" ) )
\                                             ) ||
\                                             ( hasPropertyValue( %src%, "$shapeType", "Component" ) &&
\                                               hasPropertyValue( %dst%, "$shapeType", "Object" )
\                                             )
model.constraint.link.AggregatesLink.both.1.message = "Aggregation is allowed between elements of same type, between Node and Components/Objects or between Component and Objects"
model.constraint.link.AggregatesLink.both.2 = %src% != %dst%
model.constraint.link.AggregatesLink.both.2.message = "Self-Aggregation is not allowed"

model.constraint.link.SubscribesLink.source.1 = hasPropertyValue( "$shapeType", "BusinessEntity" ) ||
\                                               hasPropertyValue( "$shapeType", "BusinessWorker" ) ||
\                                               hasPropertyValue( "$shapeType", "Actor" )
model.constraint.link.SubscribesLink.source.1.message = "Subscribes association can be drawn from BusinessWorker, BusinessEntity or Actor"
model.constraint.link.SubscribesLink.destination.1 = hasPropertyValue( "$shapeType", "BusinessEntity" )
model.constraint.link.SubscribesLink.destination.1.message = "Subscribes association can be drawn to BusinessEntity"
model.constraint.link.SubscribesLink.both.1 = %src% != %dst%
model.constraint.link.SubscribesLink.both.1.message = "Self-Subscribes association is not allowed"
model.constraint.link.IncludesLink.source.1 =      hasPropertyValue( "$shapeType", "UseCase" )
model.constraint.link.IncludesLink.source.1.message = "Includes dependency can be drawn between UseCases"
model.constraint.link.IncludesLink.destination.1 = hasPropertyValue( "$shapeType", "UseCase" )
model.constraint.link.IncludesLink.destination.1.message = "Includes dependency can be drawn between UseCases"
model.constraint.link.IncludesLink.both.1 = %src% != %dst%
model.constraint.link.IncludesLink.both.1.message = "Includes dependency can be drawn between different UseCases"
model.constraint.link.ExtendsLink.source.1 =      hasPropertyValue( "$shapeType", "UseCase" )
model.constraint.link.ExtendsLink.source.1.message = "Extends dependency can be drawn between UseCases"
model.constraint.link.ExtendsLink.destination.1 = hasPropertyValue( "$shapeType", "UseCase" )
model.constraint.link.ExtendsLink.destination.1.message = "Extends dependency can be drawn between UseCases"
model.constraint.link.ExtendsLink.both.1 = %src% != %dst%
model.constraint.link.ExtendsLink.both.1.message = "Extends dependency can be drawn between different UseCases"

model.constraint.link.GeneralizationLink.source.1 = !hasPropertyValue( "$shapeType", "Object" ) &&
\                                                   !hasPropertyValue( "$shapeType", "Note" ) &&
\                                                   !isDiagram()
model.constraint.link.GeneralizationLink.source.1.message = "This element doesn't support generalization"
model.constraint.link.GeneralizationLink.destination.1 = !hasPropertyValue( "$shapeType", "Object" ) &&
\                                                        !hasPropertyValue( "$shapeType", "Note" ) &&
\                                                        !isDiagram()
model.constraint.link.GeneralizationLink.destination.1.message = "This element doesn't support generalization"
model.constraint.link.GeneralizationLink.both.1 = getProperty( %src%, "$shapeType" ) ==
\                                                 getProperty( %dst%, "$shapeType" )
model.constraint.link.GeneralizationLink.both.1.message = "Generalization possible between elements of the same type"
model.constraint.link.GeneralizationLink.both.2 = %src% != %dst%
model.constraint.link.GeneralizationLink.both.2.message = "Self-Generalization is not allowed"



#========================
# Links shared by different diagrams
#========================
model.constraint.link.DependencyLink.source.1 = !hasPropertyValue( "$shapeType", "Note" )
model.constraint.link.DependencyLink.source.1.message = "Dependency can't be drawn from Note"
model.constraint.link.DependencyLink.destination.1 = !hasPropertyValue( "$shapeType", "Note" )
model.constraint.link.DependencyLink.destination.1.message = "Dependency can't be drawn to Note"
model.constraint.link.AssociatesLink.source.2 = !hasPropertyValue( "$shapeType", "Note" )
model.constraint.link.AssociatesLink.source.2.message = "Association can't be drawn from Note"
model.constraint.link.AssociatesLink.destination.2 = !hasPropertyValue( "$shapeType", "Note" )
model.constraint.link.AssociatesLink.destination.2.message = "Association can't be drawn to Note"
