Salome HOME
upgraded swig support from v4.0.2 to v4.1.1
[modules/shaper.git] / src / PythonAddons / macros / rectangle / feature.py
old mode 100644 (file)
new mode 100755 (executable)
index 9e09564..090d40a
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+# Copyright (C) 2014-2022  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -105,20 +105,20 @@ class SketchPlugin_Rectangle(model.Feature):
     def initAttributes(self):
         """Override Feature.initAttributes()"""
         # Flag whether the rectangle is accessory
-        self.data().addAttribute(self.AUXILIARY_ID(), ModelAPI.ModelAPI_AttributeBoolean_typeId())
+        self.data().addAttribute(self.AUXILIARY_ID(), ModelAPI.ModelAPI_AttributeBoolean.typeId())
         # Creating corners of the rectangle
-        self.data().addAttribute(self.START_ID(), GeomDataAPI.GeomDataAPI_Point2D_typeId())
-        self.data().addAttribute(self.END_ID(), GeomDataAPI.GeomDataAPI_Point2D_typeId())
+        self.data().addAttribute(self.START_ID(), GeomDataAPI.GeomDataAPI_Point2D.typeId())
+        self.data().addAttribute(self.END_ID(), GeomDataAPI.GeomDataAPI_Point2D.typeId())
         # Creating list to store lines
-        self.data().addAttribute(self.LINES_LIST_ID(), ModelAPI.ModelAPI_AttributeRefList_typeId())
+        self.data().addAttribute(self.LINES_LIST_ID(), ModelAPI.ModelAPI_AttributeRefList.typeId())
         ModelAPI.ModelAPI_Session.get().validators().registerNotObligatory(self.getKind(), self.LINES_LIST_ID())
         # Type of rectangle
-        self.data().addAttribute(self.RECTANGLE_TYPE_ID(), ModelAPI.ModelAPI_AttributeString_typeId())
+        self.data().addAttribute(self.RECTANGLE_TYPE_ID(), ModelAPI.ModelAPI_AttributeString.typeId())
         # Center and corner of the rectangle
-        self.data().addAttribute(self.CENTER_ID(), GeomDataAPI.GeomDataAPI_Point2D_typeId())
-        self.data().addAttribute(self.CORNER_ID(), GeomDataAPI.GeomDataAPI_Point2D_typeId())
+        self.data().addAttribute(self.CENTER_ID(), GeomDataAPI.GeomDataAPI_Point2D.typeId())
+        self.data().addAttribute(self.CORNER_ID(), GeomDataAPI.GeomDataAPI_Point2D.typeId())
 
-        self.data().addAttribute(self.CENTER_REF_ID(), ModelAPI.ModelAPI_AttributeRefAttr_typeId())
+        self.data().addAttribute(self.CENTER_REF_ID(), ModelAPI.ModelAPI_AttributeRefAttr.typeId())
         ModelAPI.ModelAPI_Session.get().validators().registerNotObligatory(self.getKind(), self.CENTER_REF_ID())
 
     def isMacro(self):
@@ -156,8 +156,8 @@ class SketchPlugin_Rectangle(model.Feature):
                 aRefAttrA.setAttr(aPrevLine.attribute("EndPoint"))
                 aRefAttrB.setAttr(aLine.attribute("StartPoint"))
                 aStartPoints.append(aLine.attribute("StartPoint"))
-            # Flags which show horizontal or vertical constraint is build for correponding line
-            self.__isHV = [False, False, False, False]
+            # Flags which show perpendicular constraint is build for correponding line
+            self.__isPERP = [False, False, False]
             # Update coordinates of created lines
             self.updateLines()
             # Create auxiliary diagonals in case of centered rectangle
@@ -186,21 +186,24 @@ class SketchPlugin_Rectangle(model.Feature):
                         aCoincidence = self.__sketch.addFeature("SketchConstraintCoincidence")
                         aCoincidence.refattr("ConstraintEntityA").setAttr(refPnt)
                         aCoincidence.refattr("ConstraintEntityB").setObject(line)
-        # Add horizontal and vertical constraint for the lines which already have result
-        for i in range (0, 4):
-            if self.__isHV[i]:
+        # Perpendicular for the lines which already have result
+        for i in range (0, 3):
+            if self.__isPERP[i]:
                 continue
-            aLine = ModelAPI.objectToFeature(aLinesList.object(i))
-            aLineResult = aLine.lastResult()
-            if aLineResult is None:
+            aLine_A = ModelAPI.objectToFeature(aLinesList.object(i))
+            aLineResult_A = aLine_A.lastResult()
+            if aLineResult_A is None:
+                continue
+            aLine_B = ModelAPI.objectToFeature(aLinesList.object(i+1))
+            aLineResult_B = aLine_B.lastResult()
+            if aLineResult_B is None:
                 continue
-            aHVName = "SketchConstraintHorizontal"
-            if i % 2 == 1:
-                aHVName = "SketchConstraintVertical"
-            aHVConstraint = self.__sketch.addFeature(aHVName)
-            aRefAttrA = aHVConstraint.refattr("ConstraintEntityA")
-            aRefAttrA.setObject(aLine.lastResult())
-            self.__isHV[i] = True
+            aHVConstraint = self.__sketch.addFeature("SketchConstraintPerpendicular")
+            refattrA = aHVConstraint.refattr("ConstraintEntityA")
+            refattrA.setObject(aLine_A.lastResult())
+            refattrB = aHVConstraint.refattr("ConstraintEntityB")
+            refattrB.setObject(aLine_B.lastResult())
+            self.__isPERP[i] = True
 
     def attributeChanged(self, theID):
         if theID == self.START_ID() or theID == self.END_ID() or theID == self.CENTER_ID() or theID == self.CENTER_REF_ID() or theID == self.CORNER_ID():