Salome HOME
GPUSPHGUI: add an option to Offset Surface opreation
[modules/geom.git] / src / GEOM_SWIG / geomBuilder.py
index a54af471d2632b271945317b7cf42b42b7742c9e..79dd09036de55ee8e4242e7684c947403e854273 100644 (file)
 ## vertices = geompy.SubShapeAll(box, geomBuilder.ShapeType['VERTEX'])
 ## # only 5 first vertices will be published, with default names
 ## print len(vertices)
-## # note, that result value still containes all 8 vertices
+## # note, that result value still contains all 8 vertices
 ## geompy.addToStudyAuto(-1) # disable automatic publication
 ## @endcode
 ##
@@ -976,7 +976,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         #                            in place of sub-shapes of the first argument,
         #                            because the whole shape corresponds to the first argument.
         #                            Mainly to be used after transformations, but it also can be
-        #                            usefull after partition with one object shape, and some other
+        #                            useful after partition with one object shape, and some other
         #                            operations, where only the first argument has to be considered.
         #                            If theObject has only one argument shape, this flag is automatically
         #                            considered as True, not regarding really passed value.
@@ -1002,7 +1002,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
                                    in place of sub-shapes of the first argument,
                                    because the whole shape corresponds to the first argument.
                                    Mainly to be used after transformations, but it also can be
-                                   usefull after partition with one object shape, and some other
+                                   useful after partition with one object shape, and some other
                                    operations, where only the first argument has to be considered.
                                    If theObject has only one argument shape, this flag is automatically
                                    considered as True, not regarding really passed value.
@@ -1027,7 +1027,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         #                            in place of sub-shapes of the first argument,
         #                            because the whole shape corresponds to the first argument.
         #                            Mainly to be used after transformations, but it also can be
-        #                            usefull after partition with one object shape, and some other
+        #                            useful after partition with one object shape, and some other
         #                            operations, where only the first argument has to be considered.
         #                            If theObject has only one argument shape, this flag is automatically
         #                            considered as True, not regarding really passed value.
@@ -1053,7 +1053,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
                                    in place of sub-shapes of the first argument,
                                    because the whole shape corresponds to the first argument.
                                    Mainly to be used after transformations, but it also can be
-                                   usefull after partition with one object shape, and some other
+                                   useful after partition with one object shape, and some other
                                    operations, where only the first argument has to be considered.
                                    If theObject has only one argument shape, this flag is automatically
                                    considered as True, not regarding really passed value.
@@ -1560,7 +1560,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             return anObj
 
         ## Create a line, passing through the given point
-        #  and parrallel to the given direction
+        #  and parallel to the given direction
         #  @param thePnt Point. The resulting line will pass through it.
         #  @param theDir Direction. The resulting line will be parallel to it.
         #  @param theName Object name; when specified, this parameter is used
@@ -1574,7 +1574,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         def MakeLine(self, thePnt, theDir, theName=None):
             """
             Create a line, passing through the given point
-            and parrallel to the given direction
+            and parallel to the given direction
 
             Parameters:
                 thePnt Point. The resulting line will pass through it.
@@ -3893,7 +3893,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         #  possible to generate groups along with the result by means of
         #  setting the flag \a IsGenerateGroups.<BR>
         #  If \a thePath is a closed edge or wire and \a IsGenerateGroups is
-        #  set, an error is occured. If \a thePath is not closed edge/wire,
+        #  set, an error is occurred. If \a thePath is not closed edge/wire,
         #  the following groups are returned:
         #  - If \a theBase is unclosed edge or wire: "Down", "Up", "Side1",
         #    "Side2";
@@ -3919,8 +3919,8 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         #         publication is switched on, default value is used for result name.
         #
         #  @return New GEOM.GEOM_Object, containing the created pipe if 
-        #          \a IsGenerateGroups is not set. Otherwise it returns new
-        #          GEOM.ListOfGO. Its first element is the created pipe, the
+        #          \a IsGenerateGroups is not set. Otherwise it returns a
+        #          list of GEOM.GEOM_Object. Its first element is the created pipe, the
         #          remaining ones are created groups.
         #
         #  @ref tui_creation_pipe "Example"
@@ -3933,7 +3933,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             possible to generate groups along with the result by means of
             setting the flag IsGenerateGroups.
             If thePath is a closed edge or wire and IsGenerateGroups is
-            set, an error is occured. If thePath is not closed edge/wire,
+            set, an error is occurred. If thePath is not closed edge/wire,
             the following groups are returned:
             - If theBase is unclosed edge or wire: "Down", "Up", "Side1",
               "Side2";
@@ -3959,8 +3959,8 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
 
             Returns:
                 New GEOM.GEOM_Object, containing the created pipe if 
-                IsGenerateGroups is not set. Otherwise it returns new
-                GEOM.ListOfGO. Its first element is the created pipe, the
+                IsGenerateGroups is not set. Otherwise it returns a
+                list of GEOM.GEOM_Object. Its first element is the created pipe, the
                 remaining ones are created groups.
             """
             # Example: see GEOM_TestAll.py
@@ -4182,7 +4182,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         ## Create a shape by extrusion of the profile shape along
         #  the path shape. This function is used only for debug pipe
         #  functionality - it is a version of function MakePipeWithShellSections()
-        #  which give a possibility to recieve information about
+        #  which give a possibility to receive information about
         #  creating pipe between each pair of sections step by step.
         @ManageTransactions("PrimOp")
         def MakePipeWithShellSectionsBySteps(self, theSeqBases, theSeqSubBases,
@@ -4194,7 +4194,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             the path shape. This function is used only for debug pipe
             functionality - it is a version of previous function
             geompy.MakePipeWithShellSections() which give a possibility to
-            recieve information about creating pipe between each pair of
+            receive information about creating pipe between each pair of
             sections step by step.
             """
             res = []
@@ -6383,7 +6383,8 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
 
         ## Explode a shape on sub-shapes of a given type.
         #  Sub-shapes will be sorted taking into account their gravity centers,
-        #  to provide stable order of sub-shapes.
+        #  to provide stable order of sub-shapes. Please see
+        #  @ref sorting_shapes_page "Description of Sorting Shapes Algorithm".
         #  If the shape itself matches the type, it is also returned.
         #  @param aShape Shape to be exploded.
         #  @param aType Type of sub-shapes to be retrieved (see ShapeType())
@@ -6420,7 +6421,8 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
 
         ## Explode a shape on sub-shapes of a given type.
         #  Sub-shapes will be sorted taking into account their gravity centers,
-        #  to provide stable order of sub-shapes.
+        #  to provide stable order of sub-shapes. Please see
+        #  @ref sorting_shapes_page "Description of Sorting Shapes Algorithm".
         #  @param aShape Shape to be exploded.
         #  @param aType Type of sub-shapes to be retrieved (see ShapeType())
         #  @return List of IDs of sub-shapes.
@@ -6446,6 +6448,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
 
         ## Obtain a compound of sub-shapes of <VAR>aShape</VAR>,
         #  selected by they indices in sorted list of all sub-shapes of type <VAR>aType</VAR>.
+        #  Please see @ref sorting_shapes_page "Description of Sorting Shapes Algorithm".
         #  Each index is in range [1, Nb_Sub-Shapes_Of_Given_Type]
         #  @param aShape Shape to get sub-shape of.
         #  @param ListOfInd List of sub-shapes indices.
@@ -6486,7 +6489,8 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         ## Extract shapes (excluding the main shape) of given type.
         #  @param aShape The shape.
         #  @param aType  The shape type (see ShapeType())
-        #  @param isSorted Boolean flag to switch sorting on/off.
+        #  @param isSorted Boolean flag to switch sorting on/off. Please see
+        #         @ref sorting_shapes_page "Description of Sorting Shapes Algorithm".
         #  @param theName Object name; when specified, this parameter is used
         #         for result publication in the study. Otherwise, if automatic
         #         publication is switched on, default value is used for result name.
@@ -7374,7 +7378,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         #         publication is switched on, default value is used for result name.
         #
         #  @return [\a status, \a theClosedWires, \a theOpenWires]
-        #  \n \a status: FALSE, if an error(s) occured during the method execution.
+        #  \n \a status: FALSE, if an error(s) occurred during the method execution.
         #  \n \a theClosedWires: Closed wires on the free boundary of the given shape.
         #  \n \a theOpenWires: Open wires on the free boundary of the given shape.
         #
@@ -7393,7 +7397,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
 
             Returns:
                 [status, theClosedWires, theOpenWires]
-                 status: FALSE, if an error(s) occured during the method execution.
+                 status: FALSE, if an error(s) occurred during the method execution.
                  theClosedWires: Closed wires on the free boundary of the given shape.
                  theOpenWires: Open wires on the free boundary of the given shape.
             """
@@ -8090,7 +8094,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         #      @param ListRemoveInside Shapes, inside which the results will be deleted.
         #         Each shape from theRemoveInside must belong to theShapes also.
         #      @param RemoveWebs If TRUE, perform Glue 3D algorithm.
-        #      @param ListMaterials Material indices for each shape. Make sence,
+        #      @param ListMaterials Material indices for each shape. Make sense,
         #         only if theRemoveWebs is TRUE.
         #
         #  @return New GEOM.GEOM_Object, containing the result shapes.
@@ -8132,7 +8136,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
                 ListRemoveInside Shapes, inside which the results will be deleted.
                                  Each shape from theRemoveInside must belong to theShapes also.
                 RemoveWebs If TRUE, perform Glue 3D algorithm.
-                ListMaterials Material indices for each shape. Make sence, only if theRemoveWebs is TRUE.
+                ListMaterials Material indices for each shape. Make sense, only if theRemoveWebs is TRUE.
 
             Returns:
                 New GEOM.GEOM_Object, containing the result shapes.
@@ -9224,14 +9228,15 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             """
             theOffset, Parameters = ParseParameters(theOffset)
             if theCopy:
-                anObj = self.TrsfOp.OffsetShapeCopy(theObject, theOffset)
+                anObj = self.TrsfOp.OffsetShapeCopy(theObject, theOffset, True)
             else:
-                anObj = self.TrsfOp.OffsetShape(theObject, theOffset)
+                anObj = self.TrsfOp.OffsetShape(theObject, theOffset, True)
             RaiseIfFailed("Offset", self.TrsfOp)
             anObj.SetParameters(Parameters)
             return anObj
 
-        ## Create new object as offset of the given one.
+        ## Create new object as offset of the given one. Gap between two adjacent
+        #  offset surfaces is filled by a pipe.
         #  @param theObject The base object for the offset.
         #  @param theOffset Offset value.
         #  @param theName Object name; when specified, this parameter is used
@@ -9240,11 +9245,13 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         #
         #  @return New GEOM.GEOM_Object, containing the offset object.
         #
+        #  @sa MakeOffsetIntersectionJoin
         #  @ref tui_offset "Example"
         @ManageTransactions("TrsfOp")
         def MakeOffset(self, theObject, theOffset, theName=None):
             """
-            Create new object as offset of the given one.
+            Create new object as offset of the given one. Gap between adjacent
+            offset surfaces is filled by a pipe.
 
             Parameters:
                 theObject The base object for the offset.
@@ -9263,7 +9270,48 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             """
             # Example: see GEOM_TestAll.py
             theOffset, Parameters = ParseParameters(theOffset)
-            anObj = self.TrsfOp.OffsetShapeCopy(theObject, theOffset)
+            anObj = self.TrsfOp.OffsetShapeCopy( theObject, theOffset, True )
+            RaiseIfFailed("OffsetShapeCopy", self.TrsfOp)
+            anObj.SetParameters(Parameters)
+            self._autoPublish(anObj, theName, "offset")
+            return anObj
+
+        ## Create new object as offset of the given one. Gap between adjacent
+        #  offset surfaces is filled by extending and intersecting them.
+        #  @param theObject The base object for the offset.
+        #  @param theOffset Offset value.
+        #  @param theName Object name; when specified, this parameter is used
+        #         for result publication in the study. Otherwise, if automatic
+        #         publication is switched on, default value is used for result name.
+        #
+        #  @return New GEOM.GEOM_Object, containing the offset object.
+        #
+        #  @sa MakeOffset
+        #  @ref tui_offset "Example"
+        @ManageTransactions("TrsfOp")
+        def MakeOffsetIntersectionJoin(self, theObject, theOffset, theName=None):
+            """
+            Create new object as offset of the given one. Gap between adjacent
+            offset surfaces is filled by extending and intersecting them.
+
+            Parameters:
+                theObject The base object for the offset.
+                theOffset Offset value.
+                theName Object name; when specified, this parameter is used
+                        for result publication in the study. Otherwise, if automatic
+                        publication is switched on, default value is used for result name.
+
+            Returns:
+                New GEOM.GEOM_Object, containing the offset object.
+
+            Example of usage:
+                 box = geompy.MakeBox(20, 20, 20, 200, 200, 200)
+                 # create a new box extended by 70
+                 offset = geompy.MakeOffsetIntersectionJoin(box, 70.)
+            """
+            # Example: see GEOM_TestAll.py
+            theOffset, Parameters = ParseParameters( theOffset )
+            anObj = self.TrsfOp.OffsetShapeCopy( theObject, theOffset, False )
             RaiseIfFailed("OffsetShapeCopy", self.TrsfOp)
             anObj.SetParameters(Parameters)
             self._autoPublish(anObj, theName, "offset")
@@ -10273,14 +10321,14 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             self._autoPublish(anObj, theName, "chamfer")
             return anObj
 
-        ## The Same that MakeChamferFaces() but with params theD is chamfer lenght and
+        ## The Same that MakeChamferFaces() but with params theD is chamfer length and
         #  theAngle is Angle of chamfer (angle in radians or a name of variable which defines angle in degrees)
         #
         #  @ref swig_FilletChamfer "Example"
         @ManageTransactions("LocalOp")
         def MakeChamferFacesAD(self, theShape, theD, theAngle, theFaces, theName=None):
             """
-            The Same that geompy.MakeChamferFaces but with params theD is chamfer lenght and
+            The Same that geompy.MakeChamferFaces but with params theD is chamfer length and
             theAngle is Angle of chamfer (angle in radians or a name of variable which defines angle in degrees)
             """
             flag = False
@@ -10331,12 +10379,12 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             self._autoPublish(anObj, theName, "chamfer")
             return anObj
 
-        ## The Same that MakeChamferEdges() but with params theD is chamfer lenght and
+        ## The Same that MakeChamferEdges() but with params theD is chamfer length and
         #  theAngle is Angle of chamfer (angle in radians or a name of variable which defines angle in degrees)
         @ManageTransactions("LocalOp")
         def MakeChamferEdgesAD(self, theShape, theD, theAngle, theEdges, theName=None):
             """
-            The Same that geompy.MakeChamferEdges but with params theD is chamfer lenght and
+            The Same that geompy.MakeChamferEdges but with params theD is chamfer length and
             theAngle is Angle of chamfer (angle in radians or a name of variable which defines angle in degrees)
             """
             flag = False
@@ -10575,6 +10623,8 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         ## Get summarized length of all wires,
         #  area of surface and volume of the given shape.
         #  @param theShape Shape to define properties of.
+        #  @param theTolerance maximal relative error of area
+        #         and volume computation.
         #  @return [theLength, theSurfArea, theVolume]\n
         #  theLength:   Summarized length of all wires of the given shape.\n
         #  theSurfArea: Area of surface of the given shape.\n
@@ -10582,13 +10632,15 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         #
         #  @ref tui_basic_properties_page "Example"
         @ManageTransactions("MeasuOp")
-        def BasicProperties(self,theShape):
+        def BasicProperties(self,theShape, theTolerance=1.e-6):
             """
             Get summarized length of all wires,
             area of surface and volume of the given shape.
 
             Parameters:
                 theShape Shape to define properties of.
+                theTolerance maximal relative error of area
+                             and volume computation.
 
             Returns:
                 [theLength, theSurfArea, theVolume]
@@ -10597,7 +10649,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
                  theVolume:   Volume of the given shape.
             """
             # Example: see GEOM_TestMeasures.py
-            aTuple = self.MeasuOp.GetBasicProperties(theShape)
+            aTuple = self.MeasuOp.GetBasicProperties(theShape, theTolerance)
             RaiseIfFailed("GetBasicProperties", self.MeasuOp)
             return aTuple
 
@@ -11439,6 +11491,24 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             RaiseIfFailed("CheckSelfIntersectionsFast", self.MeasuOp)
             return IsValid
 
+        ## Check boolean and partition operations agruments.
+        #  @param theShape the agrument of an operation to be checked
+        #  @return TRUE if the agrument is valid for a boolean or partition
+        #          operation; FALSE otherwise.
+        @ManageTransactions("MeasuOp")
+        def CheckBOPArguments(self, theShape):
+            """
+            Check boolean and partition operations agruments.
+
+            Parameters:
+                theShape the agrument of an operation to be checked
+
+            Returns:
+                TRUE if the agrument is valid for a boolean or partition
+                operation; FALSE otherwise.
+            """
+            return self.MeasuOp.CheckBOPArguments(theShape)
+
         ## Detect intersections of the given shapes with algorithm based on mesh intersections.
         #  @param theShape1 First source object
         #  @param theShape2 Second source object
@@ -11658,8 +11728,14 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             return self.ImportFile(theFileName, theFormatName, theName)
 
         ## Read a shape from the binary stream, containing its bounding representation (BRep).
-        #  @note This method will not be dumped to the python script by DumpStudy functionality.
-        #  @note GEOM.GEOM_Object.GetShapeStream() method can be used to obtain the shape's BRep stream.
+        #
+        #  @note As the byte-stream representing the shape data can be quite large, this method
+        #  is not automatically dumped to the Python script with the DumpStudy functionality;
+        #  so please use this method carefully, only for strong reasons.
+        #  
+        #  @note GEOM.GEOM_Object.GetShapeStream() method can be used to obtain the shape's
+        #  data stream.
+        #
         #  @param theStream The BRep binary stream.
         #  @param theName Object name; when specified, this parameter is used
         #         for result publication in the study. Otherwise, if automatic
@@ -11686,6 +11762,11 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
                 New GEOM_Object, containing the shape, read from theStream.
             """
             # Example: see GEOM_TestOthers.py
+            if not theStream:
+                # this is the workaround to ignore invalid case when data stream is empty
+                if int(os.getenv("GEOM_IGNORE_RESTORE_SHAPE", "0")) > 0:
+                    print "WARNING: Result of RestoreShape is a NULL shape!"
+                    return None
             anObj = self.InsertOp.RestoreShape(theStream)
             RaiseIfFailed("RestoreShape", self.InsertOp)
             self._autoPublish(anObj, theName, "restored")
@@ -12732,7 +12813,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
         ## Build all possible propagation groups.
         #  Propagation group is a set of all edges, opposite to one (main)
         #  edge of this group directly or through other opposite edges.
-        #  Notion of Opposite Edge make sence only on quadrangle face.
+        #  Notion of Opposite Edge make sense only on quadrangle face.
         #  @param theShape Shape to build propagation groups on.
         #  @param theName Object name; when specified, this parameter is used
         #         for result publication in the study. Otherwise, if automatic
@@ -12747,7 +12828,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             Build all possible propagation groups.
             Propagation group is a set of all edges, opposite to one (main)
             edge of this group directly or through other opposite edges.
-            Notion of Opposite Edge make sence only on quadrangle face.
+            Notion of Opposite Edge make sense only on quadrangle face.
 
             Parameters:
                 theShape Shape to build propagation groups on.
@@ -13172,7 +13253,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             return aType
 
         ## Convert a type of geom object from id to string value
-        #  @param theId is a GEOM obect type id.
+        #  @param theId is a GEOM object type id.
         #  @return type of geom object (POINT, VECTOR, PLANE, LINE, TORUS, ... )
         #  @ref swig_GetType "Example"
         def ShapeIdToType(self, theId):
@@ -13180,7 +13261,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             Convert a type of geom object from id to string value
 
             Parameters:
-                theId is a GEOM obect type id.
+                theId is a GEOM object type id.
 
             Returns:
                 type of geom object (POINT, VECTOR, PLANE, LINE, TORUS, ... )
@@ -13404,7 +13485,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             self.addToStudyInFather(shape, group_edges, "Group of edges with " + `min_length`
                                     + left_str + "length" + right_str + `max_length`)
 
-            sg.updateObjBrowser(1)
+            sg.updateObjBrowser(True)
 
             return group_edges