Salome HOME
Dump with geometrical selection
[modules/shaper.git] / src / PythonAddons / macros / box / feature.py
index 6be8f29edddfb3d3097db4ff03aa255c8d5b8717..72fc83d530db9e88a17c9ff9f035fc6dd511fadf 100644 (file)
@@ -1,10 +1,30 @@
+## Copyright (C) 2014-2017  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
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
 """Box macro-feature
 Authors: Renaud Nedelec - Daniel Brunier-Coulin
 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 """
 
-import model
-import geom
+from salome.shaper import model
+from salome.shaper import geom
 
 
 class BoxFeature(model.Feature):
@@ -22,7 +42,7 @@ class BoxFeature(model.Feature):
     @staticmethod
     def ID():
         """Return Id of the feature."""
-        return "Box"
+        return "Box_script"
 
     @staticmethod
     def WIDTH_ID():
@@ -67,15 +87,23 @@ class BoxFeature(model.Feature):
 
         line = model.addPolygon(self.base, p1, p2, p3, p4)
 
-        self.base.setParallel(line[0], line[2])
-        self.base.setParallel(line[1], line[3])
-        self.base.setPerpendicular(line[0], line[3])
+        self.base.setFixed(line[0].startPoint())
+        self.base.setVertical(line[0])
 
         # Setting the size of the base with default values
         # Width
-        self.width = self.base.setLength(line[0], 50)  # Keeps the constraint for edition
+        self.width = self.base.setLength(line[3], 50)  # Keeps the constraint for edition
         # Length
-        self.length = self.base.setLength(line[3], 50)  # Keeps the constraint for edition
+        self.length = self.base.setLength(line[0], 50)  # Keeps the constraint for edition
+
+        # Keeping the rectangle
+        self.base.setParallel(line[0], line[2])
+        self.base.setParallel(line[1], line[3])
+        self.base.setPerpendicular(line[0], line[3])
+
+        # execute sketch
+        mypart.setCurrentFeature(self.base.feature(), False)
+        model.updateFeatures()
 
         # Creating the extrusion (the box) at default size
         # A box result