Пример #1
0
        public bool equals(Trigger trigger)
        {
            if (mEvent.Type != trigger.mEvent.Type)
                return false;
            if (mEvent.Type == "SignalEvent")
            {
               // StreamWriter file = MascaretApplication.Instance.logfile;
                if (mEvent as SignalEvent != null && ((SignalEvent)mEvent).name == ((SignalEvent)trigger.mEvent).Signal.Classifier.name)
                {
                    return true;
                }
                else
                    return false;
            }
            else if (mEvent.Type == "ChangeEvent")
            {
                Expression exp1 = ((Expression)((ChangeEvent)mEvent).ChangeExpression);
                Expression exp2 = ((Expression)((ChangeEvent)trigger.MEvent).ChangeExpression);
                if (exp1.ExpressionValue == exp2.ExpressionValue)
                    return true;
                else return false;
            }
            else if (mEvent.Type == "TimeEvent")
            {
                LiteralReal value1 = (LiteralReal)((TimeEvent)mEvent).When;
                LiteralReal value2 = (LiteralReal)((TimeEvent)trigger.MEvent).When;

                if (value1.RValue == value2.RValue)
                    return true;
                else return false;
            }
            else
                return false;
        }
 public void addTime(double time)
 {
     Trigger trigger = new Trigger("time");
     TimeEvent te = new TimeEvent("time");
     LiteralReal lValue = new LiteralReal(time);
     te.When = lValue;
     trigger.MEvent = te;
     eventQueue.Add(trigger);
     restart();
 }
 public void addSignal(InstanceSpecification signal)
 {
     // StreamWriter file = MascaretApplication.Instance.logfile;
       //  file.WriteLine("recu signal : " + signal.name + " par " + Host.name); file.Flush();
     Trigger trigger = new Trigger(signal.name);
     SignalEvent se = new SignalEvent(signal.name);
     se.Signal = signal;
     trigger.MEvent = se;
     eventQueue.Add(trigger);
     //restart();
 }
Пример #4
0
        //FinalNode, Merge et Decision devraent �tre des activityNode !!
        public void addActivityNode(XElement node, Activity activity)
        {
            MascaretApplication.Instance.VRComponentFactory.Log("New activity node");
            string type = "";
            string id = "";
            if (node.Attribute("{http://schema.omg.org/spec/XMI/2.1}type") != null)
                type = node.Attribute("{http://schema.omg.org/spec/XMI/2.1}type").Value;
            else
                type = node.Attribute("{http://www.omg.org/spec/XMI/20131001}type").Value;

            MascaretApplication.Instance.VRComponentFactory.Log(" Type : " + type);

            if (node.Attribute("{http://schema.omg.org/spec/XMI/2.1}id") != null)
                id = node.Attribute("{http://schema.omg.org/spec/XMI/2.1}id").Value;
            else
                id = node.Attribute("{http://www.omg.org/spec/XMI/20131001}id").Value;
            MascaretApplication.Instance.VRComponentFactory.Log(" ID : " + id);

            string name = "";
            if (node.Attribute("name") != null)
                name = node.Attribute("name").Value;
            else name = id;
            MascaretApplication.Instance.VRComponentFactory.Log(" Name : " + name);

            string idPartition = "";
            if (node.Attribute("inPartition") != null)
                idPartition = node.Attribute("inPartition").Value;

            MascaretApplication.Instance.VRComponentFactory.Log(id);
            MascaretApplication.Instance.VRComponentFactory.Log(type);
            MascaretApplication.Instance.VRComponentFactory.Log(name);
            MascaretApplication.Instance.VRComponentFactory.Log(idPartition);

            ActivityNode actNode = null;

            //Debug.Log(" TYPE NODE : " + type);

            if (type == "uml:InitialNode")
            {
                actNode = new InitialNode();
                activity.Initial = actNode;
                actNode.name = "Initial";
            }
            else if (type == "uml:FinalNode" || type == "uml:ActivityFinalNode")
            {
                actNode = new FinalNode();
            }
            else if (type == "uml:LoopNode")
            {
                addActivityGroup(node, activity);
            }
            else if (type == "uml:ForkNode")
            {
                actNode = new ForkNode();
            }
            else if (type == "uml:JoinNode")
            {
                actNode = new JoinNode();
            }
            else if (type == "uml:MergeNode")
            {
                actNode = new MergeNode();
            }
            /*else if (type == "uml:DecisionNode")
            {
                actNode = new DecisionNode();
            }*/
            else if (type == "uml:ObjectNode" || type == "uml:CentralBufferNode")
            {

                ObjectNode objNode = new ObjectNode(name);
                Classifier ressourceType = getObjectNodeType(node);
                if (ressourceType != null)
                    objNode.ResourceType = ressourceType;
                actNode = objNode;
                string type2 = node.Attribute("{http://schema.omg.org/spec/XMI/2.1}type").Value;
                if (_idClass.ContainsKey(type2))
                    ((ObjectNode)actNode).ResourceType = _idClass[type2];
            }
            else if (type == "uml:ValueSpecificationAction")
            {
                /*
                shared_ptr<XmlNode> valueNode = node->getChildByName("value");
                string expressionValue = valueNode->getProperty("value");
                shared_ptr<Expression> expression = make_shared<Expression>(expressionValue, _model->getBasicType("boolean"));
                _activityExpressions[node->getProperty("id")] = expression;
                */
            }
            else if (type == "uml:OpaqueAction")
            {
                if (isStereotypedPlayAnimation(node))
                {
                    string animationName = getAnimName(node);
                    MascaretApplication.Instance.VRComponentFactory.Log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% NEW PLAY ANIMATION : " + name + "    " + animationName);

                    ActionNode an = new ActionNode(name, "action");
                    PlayAnimationAction ap = new PlayAnimationAction();
                    ap.Description = getComment(node);
                    ap.name = name;
                    ap.Owner = activity;
                    ap.animationName = animationName;

                    an.Action = ap;
                    addPins(an, node);
                    actNode = an;
                }
            }
            else if (type == "uml:CallBehaviorAction")
            {

                ActionNode an = new ActionNode(name, "action");
                CallBehaviorAction cb = new CallBehaviorAction();
                cb.Description = getComment(node);
                cb.name = name;
                cb.Owner = activity;
                XElement beNode = node.Element("behavior");

                string opid;

                if (beNode != null) opid = beNode.Attribute("idref").Value;
                else opid = node.Attribute("behavior").Value;

                if (_idBehaviors.ContainsKey(opid))
                {
                    cb.Behavior = _idBehaviors[opid];
                }
                else
                {
                    // Debug.Log("[ModelLoader2 Info] Behavior " + opid
                    //           + " not yet found for ActionNode " + name + ". Postbone...");
                    _callBehaviors.Add(cb, opid);
                }

                an.Action = cb;
                addPins(an, node);
                actNode = an;

            }
            else if (type == "uml:CallOperationAction")
            {

                ActionNode an = new ActionNode(name, "action");
                //Debug.Log("Action Node : " +name);
                CallOperationAction act = new CallOperationAction();
                act.Description = getComment(node);
                an.Fml = getFML(node);

                act.name = name;

                act.Owner = activity;

                XElement opNode = node.Element("operation");
                if (opNode != null)
                {
                    string opid;
                    opid = opNode.Attribute("idref").Value;
                    //MascaretApplication.Instance.logfile.WriteLine("Operation ID : " + opid); MascaretApplication.Instance.logfile.Flush();
                    string stereo = getStereotype(opid);
                    MascaretApplication.Instance.VRComponentFactory.Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + name + " : " + opid + " " + stereo);
                    if (stereo != "")
                    {

                        an.Stereotype = stereo;
                    }

                    if (_idOperations.ContainsKey(opid))
                        act.Operation = _idOperations[opid];
                    else
                    {
                        //cerr << "ERREUR PAS OPERATION... " << opid<< endl;
                        _callOperations.Add(act, opid);
                    }
                }
                else
                {
                    string opid;
                    opid = node.Attribute("operation").Value;
                    // MascaretApplication.Instance.logfile.WriteLine("Operation ID : " + opid); MascaretApplication.Instance.logfile.Flush();
                    string stereo = getStereotype(opid);
                    MascaretApplication.Instance.VRComponentFactory.Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + name + " : " + opid + " " + stereo);
                    if (stereo != "")
                    {

                        an.Stereotype = stereo;
                    }

                    // MascaretApplication.Instance.logfile.WriteLine("Operation ID : " + opid); MascaretApplication.Instance.logfile.Flush();

                    if (_idOperations.ContainsKey(opid))
                    {
                        act.Operation = _idOperations[opid];
                        // MascaretApplication.Instance.logfile.WriteLine("Operation Name : " + act.Operation); MascaretApplication.Instance.logfile.Flush();

                    }
                    else
                        _callOperations.Add(act, opid);
                }
                an.Action = act;
                addPins(an, node);
                actNode = an;
            }
            else if (type == "uml:SendSignalAction")
            {
                MascaretApplication.Instance.VRComponentFactory.Log("SendSignalAction");
                ActionNode an = new ActionNode(name, "action");
                SendSignalAction act = new SendSignalAction();
                XElement sigNode = node.Element("signal");
                if (sigNode != null)
                {
                    string signame = sigNode.Attribute("name").Value;
                    if (!_signals.ContainsKey(signame))
                    {
                        Signal ns = new Signal(signame);
                        _signals.Add(signame, ns);
                    }
                    act.SignalClass = _signals[signame];
                }
                else
                {
                    string signame = "";
                    if (node.Attribute("signal") != null)
                        signame = node.Attribute("signal").Value;
                    if (!_signals.ContainsKey(signame))
                    {
                        Signal ns = new Signal(signame);
                        _signals.Add(signame, ns);
                    }

                    act.SignalClass = _signals[signame];
                }

                XElement targetNode = node.Element("argument");
                if (targetNode != null)
                {
                    string targetName = targetNode.Attribute("name").Value;
                    XElement typeNode = targetNode.Element("type");
                    string classid = "";
                    if (typeNode != null)
                        classid = typeNode.Attribute("idref").Value;
                    else
                        classid = targetNode.Attribute("type").Value;
                    act.Target = new SendSignalTarget();
                    act.Target.targetName = targetName;
                    act.Target.targetClass = _idClass[classid];
                }
                else
                {
                    targetNode = node.Element("target");
                    if (targetNode != null)
                    {
                        MascaretApplication.Instance.VRComponentFactory.Log("SendSignal Target");
                        string targetName = targetNode.Attribute("name").Value;
                        string classid = targetNode.Attribute("type").Value;
                        MascaretApplication.Instance.VRComponentFactory.Log("name : " + targetName);
                        MascaretApplication.Instance.VRComponentFactory.Log("name : " + targetName + " : " + _idClass[classid]);

                        act.Target = new SendSignalTarget();
                        act.Target.targetName = targetName;
                        act.Target.targetClass = _idClass[classid];

                    }
                    else MascaretApplication.Instance.VRComponentFactory.Log("No target");
                }
                an.Action = act;
                addPins(an, node);
                actNode = an;
            }
            else if (type == "uml:AddStructuralFeatureValueAction")
            {
                //cerr << " ############# Found a AddStructuralFeatureValueAction : " << endl;
                /*
                shared_ptr<ActionNode> an = make_shared<ActionNode>(name);
                shared_ptr<Classifier> type;
                shared_ptr<XmlNode> pinNode = node->getChildByName("object");

                string attrName = pinNode->getProperty("name");

                cerr << " Name == " << attrName << endl;

                shared_ptr<XmlNode> typeNode = pinNode->getChildByName("type");
                if (typeNode && typeNode->getProperty("type") == "uml:PrimitiveType")
                {
                    string href = typeNode->getProperty("href");
                    string strType = href.substr(href.rfind('#') + 1);
                    boost::to_lower(strType);
                    type = _model->getBasicType(strType);
                }

                shared_ptr<XmlNode> valueNode = pinNode->getChildByName("value");
                if (valueNode)
                {
                    string value = valueNode->getProperty("value");
                    cerr << "    VALUE : " << value << endl;
                    shared_ptr<Expression> expression = make_shared<Expression>(value, type);
                    shared_ptr<AddStructuralFeatureValueAction> act =
                        make_shared<AddStructuralFeatureValueAction>();
                    act->setValue(expression);
                    act->setProperty(attrName);
                    an->setAction(act);
                }
                actNode = an;
                */

            }
            else if (type == "uml:AcceptEventAction")
            {
                MascaretApplication.Instance.VRComponentFactory.Log("New uml:AcceptEventAction");
                ActionNode an = new ActionNode(name, "action");
                AcceptEventAction act = new AcceptEventAction();

                XElement triggerNode = node.Element("trigger");
                if (triggerNode != null)
                {
                    MascaretApplication.Instance.VRComponentFactory.Log("trigger node found");

                    Trigger trigger = new Trigger(name);
                    MascaretApplication.Instance.VRComponentFactory.Log("Debug : " + name);
                    string idT = "";
                    if (triggerNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}id") != null)
                        idT = triggerNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}id").Value;
                    else
                        idT = triggerNode.Attribute("{http://www.omg.org/spec/XMI/20131001}id").Value;

                    trigger.Id = idT;
                    MascaretApplication.Instance.VRComponentFactory.Log(trigger.Id);

                    if (triggerNode.Attribute("event") != null)
                    {
                        string idEvent = triggerNode.Attribute("event").Value;

                        if (_events.ContainsKey(idEvent))
                        {
                            trigger.MEvent = _events[idEvent];
                            act.setTrigger(trigger);
                        }
                        else
                            MascaretApplication.Instance.VRComponentFactory.Log("Could not find event : " + idEvent);
                    }
                }
                an.Action = act;
                addPins(an, node);
                actNode = an;

                MascaretApplication.Instance.VRComponentFactory.Log(" Fin AcceptEventAction");

            }
            // ...
            else
            {
                //Debug.Log("Unknown state: " + type);
            }

            if (actNode != null)
            {
                _activityNodes.Add(id, actNode);
                activity.addNode(actNode);
                //cerr << "searching _partitions for '" << idPartition << "'" << endl;
                if (_partitions.ContainsKey(idPartition))
                {
                    actNode.Partitions.Add(_partitions[idPartition]);
                    _partitions[idPartition].Node.Add(actNode);
                }
                actNode.Summary = getSummary(node);
                actNode.Description = getComment(node);
                actNode.Tags = getTags(node);
            }
        }
Пример #5
0
        //non gestion des triggers
        //Attention ! Les Opaque expressions ne sont pas impl�ment� mais sont utilis� pour le moment dans les modelLoader
        //(par contre les expressions existe - c'est du ocl)
        public void addMachineTransition(XElement node, StateMachine machine, Dictionary<string, Vertex> vertices)
        {
            //shared_ptr<Operation> op;

            //    StreamWriter fileT = MascaretApplication.Instance.logfile;
            Transition t = new Transition();
            string transitionKind = "";

            if (node.Attribute("kind") != null)
                transitionKind = node.Attribute("kind").Value;
            t.Description = getComment(node);
            t.Summary = getSummary(node);
            t.Tags = getTags(node);
            if (transitionKind != "internal")
            {
                //cerr << "Not internal" << endl;
                Region region = machine.Region[machine.Region.Count - 1];
                region.Transitions.Add(t);
            }
            //   fileT.WriteLine("-------------------------------------------");
            //   fileT.WriteLine("Transition : " + transitionKind); fileT.Flush();

            // Trigger

            XElement triggerNode;
            triggerNode = node.Element("trigger");
            if (triggerNode != null)
            {
                if (triggerNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}idref") != null)
                {
                    string idRef = triggerNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}idref").Value;
                    MascaretEvent evt = this._events[idRef];
                    if (evt != null)
                    {
                        //    fileT.WriteLine("Trigger : " + evt.name);
                        Trigger trigger = new Trigger(evt.name);
                        trigger.MEvent = evt;
                        t.Trigger.Add(trigger);
                    }
                }
                else
                {
                    string triggerName = triggerNode.Attribute("name").Value;

                    if (triggerNode.Attribute("event") != null)
                    {
                        //cerr << "has prop event" << endl;
                        string eventID = triggerNode.Attribute("event").Value;
                        MascaretEvent evt = this._events[eventID];
                        if (evt != null)
                        {
                            //    fileT.WriteLine("Trigger : " + evt.name);
                            //   if (evt.GetType().ToString() == "Mascaret.SignalEvent") fileT.WriteLine("Trigger Class : " + ((SignalEvent)evt).SignalClass.name);
                            //   fileT.Flush();
                            Trigger trigger = new Trigger(evt.name);
                            trigger.MEvent = evt;
                            t.Trigger.Add(trigger);
                        }// else
                         //Debug.Log ("Error : Event not found for trigger : " + triggerName
                         //	+ " in machine " + machine.getFullName() );
                    }
                }
            }

            // Effect
            XElement effectNode;
            effectNode = node.Element("effect");
            if (effectNode != null)
            {
                string type = "";
                if (effectNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}type") != null)
                    type = effectNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}type").Value;
                else
                    type = effectNode.Attribute("{http://www.omg.org/spec/XMI/20131001}type").Value;

                if (type == "uml:OpaqueBehavior")
                {
                    if (effectNode.Attribute("specification") != null)
                    {
                        string opName = effectNode.Attribute("specification").Value;
                        Operation op = _idOperations[opName];

                        if (transitionKind != "internal" && op != null)
                        {
                            CallOperationAction action = new CallOperationAction();
                            t.Effect = action;
                            action.Operation = op;
                        }

                    }
                    else
                    {
                        string sigName = effectNode.Attribute("name").Value;
                        Signal sig;
                        sig = _signals[sigName];
                        SendSignalAction action = new SendSignalAction();
                        t.Effect = action;
                        action.SignalClass = sig;
                    }
                }
            }

            if (transitionKind != "internal")
            {
                // Source
                string sourceID = node.Attribute("source").Value;
                string targetID = node.Attribute("target").Value;

                //            fileT.WriteLine("Source : " + sourceID);
                //          fileT.WriteLine("Target : " + targetID);
                foreach (KeyValuePair<string, Vertex> v in vertices)
                {
                    //    fileT.WriteLine("       Vertex : " + v.Key + " = " + v.Value.name);
                }

                Vertex vertex = null;

                if (!vertices.TryGetValue(sourceID, out vertex))
                {
                }
                else
                {
                    //  fileT.WriteLine("Source : " + vertex.name);
                    t.Source = vertex;
                    vertex.Outgoing.Add(t);
                }
                // target

                if (!vertices.TryGetValue(targetID, out vertex))
                {

                }
                else
                {
                    //   fileT.WriteLine("Target : " + vertex.name);

                    t.Target = vertex;
                    vertex.Incoming.Add(t);
                }
            }
        }