Xcos MVC: fix Diagrams's 'objs' property getter and setter
[scilab.git] / scilab / modules / scicos / src / cpp / model / Link.hxx
index 6db27cd..23f6285 100644 (file)
@@ -15,7 +15,6 @@
 
 #include <string>
 #include <vector>
-#include <utility>
 
 #include "Model.hxx"
 #include "model/BaseObject.hxx"
@@ -25,53 +24,172 @@ namespace org_scilab_modules_scicos
 namespace model
 {
 
+/*
+ * List of all possible values for a Link.
+ */
+enum link_kind_t
+{
+    activation = -1,
+    regular = 1,
+    implicit = 2
+};
+
 class Link: public BaseObject
 {
     friend class ::org_scilab_modules_scicos::Model;
 
 private:
-    Link() : BaseObject(LINK), parentDiagram(0), sourcePort(0), destinationPort(0), controlPoints() {};
-    Link(const Link& o) : BaseObject(LINK), parentDiagram(o.parentDiagram), sourcePort(o.sourcePort), destinationPort(o.destinationPort), controlPoints(o.controlPoints) {};
+    Link() : BaseObject(LINK), parentDiagram(0), sourcePort(0), destinationPort(0), controlPoints(),
+        label(), thick(std::vector<double>(2)), color(1), linkKind(regular) {};
+    Link(const Link& o) : BaseObject(LINK), parentDiagram(o.parentDiagram), sourcePort(o.sourcePort), destinationPort(o.destinationPort),
+        controlPoints(o.controlPoints), label(o.label), thick(o.thick), color(o.color), linkKind(o.linkKind) {};
     ~Link() {}
 
-    ScicosID getParentDiagram() const
+    void getParentDiagram(ScicosID& v) const
     {
-        return parentDiagram;
+        v = parentDiagram;
     }
 
-    void setParentDiagram(ScicosID parentDiagram)
+    update_status_t setParentDiagram(const ScicosID v)
     {
-        this->parentDiagram = parentDiagram;
+        if (v == parentDiagram)
+        {
+            return NO_CHANGES;
+        }
+
+        parentDiagram = v;
+        return SUCCESS;
     }
 
-    const std::vector<std::pair<double, double> >& getControlPoints() const
+    void getControlPoints(std::vector<double>& v) const
     {
-        return controlPoints;
+        v = controlPoints;
     }
 
-    void setControlPoints(const std::vector<std::pair<double, double> >& controlPoints)
+    update_status_t setControlPoints(const std::vector<double>& v)
     {
-        this->controlPoints = controlPoints;
+        if (v == controlPoints)
+        {
+            return NO_CHANGES;
+        }
+
+        controlPoints = v;
+        return SUCCESS;
     }
 
-    ScicosID getDestinationPort() const
+    void getLabel(std::string& data) const
     {
-        return destinationPort;
+        data = label;
     }
 
-    void setDestinationPort(ScicosID destinationPort)
+    update_status_t setLabel(const std::string& data)
     {
-        this->destinationPort = destinationPort;
+        if (data == label)
+        {
+            return NO_CHANGES;
+        }
+
+        label = data;
+        return SUCCESS;
     }
 
-    ScicosID getSourcePort() const
+    void getThick(std::vector<double>& v) const
     {
-        return sourcePort;
+        v = thick;
     }
 
-    void setSourcePort(ScicosID sourcePort)
+    update_status_t setThick(const std::vector<double>& v)
     {
-        this->sourcePort = sourcePort;
+        if (v.size() != 2)
+        {
+            return FAIL;
+        }
+
+        if (v == thick)
+        {
+            return NO_CHANGES;
+        }
+
+        thick = v;
+        return SUCCESS;
+    }
+
+    void getColor(int& c) const
+    {
+        c = color;
+    }
+
+    update_status_t setColor(const int c)
+    {
+        if (c == color)
+        {
+            return NO_CHANGES;
+        }
+
+        color = c;
+        return SUCCESS;
+    }
+
+    void getKind(int& k) const
+    {
+        k = linkKind;
+    }
+
+    update_status_t setKind(const int k)
+    {
+        if (k == linkKind)
+        {
+            return NO_CHANGES;
+        }
+
+        // Only accepting Scilab Link kind values
+        switch (k)
+        {
+            case activation:
+                linkKind = activation;
+                break;
+            case regular:
+                linkKind = regular;
+                break;
+            case implicit:
+                linkKind = implicit;
+                break;
+            default:
+                return FAIL;
+        }
+        return SUCCESS;
+    }
+
+    void getSourcePort(ScicosID& sp) const
+    {
+        sp = sourcePort;
+    }
+
+    update_status_t setSourcePort(const ScicosID sp)
+    {
+        if (sp == sourcePort)
+        {
+            return NO_CHANGES;
+        }
+
+        sourcePort = sp;
+        return SUCCESS;
+    }
+
+    void getDestinationPort(ScicosID& dp) const
+    {
+        dp = destinationPort;
+    }
+
+    update_status_t setDestinationPort(const ScicosID dp)
+    {
+        if (dp == destinationPort)
+        {
+            return NO_CHANGES;
+        }
+
+        destinationPort = dp;
+        return SUCCESS;
     }
 
 private:
@@ -81,7 +199,13 @@ private:
     ScicosID destinationPort;
 
     // used to store, user-defined control points
-    std::vector<std::pair<double, double> > controlPoints;
+    std::vector<double> controlPoints;
+
+    std::string label;
+    std::vector<double> thick;
+    int color;
+    link_kind_t linkKind;
+
 };
 
 } /* namespace model */