+# Import/Export objects
+# -----------------------------------------------------------------------------
+
+def Import(theFileName, theFormatName):
+ """
+ * Import a shape from the BREP or IGES or STEP file
+ * (depends on given format) with given name.
+ * \param theFileName The file, containing the shape.
+ * \param theFormatName Specify format for the file reading.
+ * Available formats can be obtained with InsertOp.ImportTranslators() method.
+ * \return New GEOM_Object, containing the imported shape.
+
+ * Example: see GEOM_TestOthers.py
+ """
+ anObj = InsertOp.Import(theFileName, theFormatName)
+ if InsertOp.IsDone() == 0:
+ print "Import : ", InsertOp.GetErrorCode()
+ return anObj
+
+def ImportBREP(theFileName):
+ """
+ * Shortcut to Import() for BREP format
+
+ * Example: see GEOM_TestOthers.py
+ """
+ return Import(theFileName, "BREP")
+
+def ImportIGES(theFileName):
+ """
+ * Shortcut to Import() for IGES format
+
+ * Example: see GEOM_TestOthers.py
+ """
+ return Import(theFileName, "IGES")
+
+def ImportSTEP(theFileName):
+ """
+ * Shortcut to Import() for STEP format
+
+ * Example: see GEOM_TestOthers.py
+ """
+ return Import(theFileName, "STEP")
+
+def Export(theObject, theFileName, theFormatName):
+ """
+ * Export the given shape into a file with given name.
+ * \param theObject Shape to be stored in the file.
+ * \param theFileName Name of the file to store the given shape in.
+ * \param theFormatName Specify format for the shape storage.
+ * Available formats can be obtained with InsertOp.ImportTranslators() method.
+
+ * Example: see GEOM_TestOthers.py
+ """
+ InsertOp.Export(theObject, theFileName, theFormatName)
+ if InsertOp.IsDone() == 0:
+ print "Export : ", InsertOp.GetErrorCode()
+
+def ExportBREP(theObject, theFileName):
+ """
+ * Shortcut to Export() for BREP format
+
+ * Example: see GEOM_TestOthers.py
+ """
+ return Export(theObject, theFileName, "BREP")
+
+def ExportIGES(theObject, theFileName):
+ """
+ * Shortcut to Export() for IGES format
+
+ * Example: see GEOM_TestOthers.py
+ """
+ return Export(theObject, theFileName, "IGES")
+
+def ExportSTEP(theObject, theFileName):
+ """
+ * Shortcut to Export() for STEP format
+
+ * Example: see GEOM_TestOthers.py
+ """
+ return Export(theObject, theFileName, "STEP")
+
+# -----------------------------------------------------------------------------
+# Block operations
+# -----------------------------------------------------------------------------
+
+def MakeQuad(E1, E2, E3, E4):
+ """
+ * Create a quadrangle face from four edges. Order of Edges is not
+ * important. It is not necessary that edges share the same vertex.
+ * \param E1,E2,E3,E4 Edges for the face bound.
+ * \return New GEOM_Object, containing the created face.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.MakeQuad(E1, E2, E3, E4)
+ if BlocksOp.IsDone() == 0:
+ print "MakeQuad : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def MakeQuad2Edges(E1, E2):
+ """
+ * Create a quadrangle face on two edges.
+ * The missing edges will be built by creating the shortest ones.
+ * \param E1,E2 Two opposite edges for the face.
+ * \return New GEOM_Object, containing the created face.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.MakeQuad2Edges(E1, E2)
+ if BlocksOp.IsDone() == 0:
+ print "MakeQuad2Edges : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def MakeQuad4Vertices(V1, V2, V3, V4):
+ """
+ * Create a quadrangle face with specified corners.
+ * The missing edges will be built by creating the shortest ones.
+ * \param V1,V2,V3,V4 Corner vertices for the face.
+ * \return New GEOM_Object, containing the created face.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.MakeQuad4Vertices(V1, V2, V3, V4)
+ if BlocksOp.IsDone() == 0:
+ print "MakeQuad4Vertices : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def MakeHexa(F1, F2, F3, F4, F5, F6):
+ """
+ * Create a hexahedral solid, bounded by the six given faces. Order of
+ * faces is not important. It is not necessary that Faces share the same edge.
+ * \param F1,F2,F3,F4,F5,F6 Faces for the hexahedral solid.
+ * \return New GEOM_Object, containing the created solid.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.MakeHexa(F1, F2, F3, F4, F5, F6)
+ if BlocksOp.IsDone() == 0:
+ print "MakeHexa : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def MakeHexa2Faces(F1, F2):
+ """
+ * Create a hexahedral solid between two given faces.
+ * The missing faces will be built by creating the smallest ones.
+ * \param F1,F2 Two opposite faces for the hexahedral solid.
+ * \return New GEOM_Object, containing the created solid.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.MakeHexa2Faces(F1, F2)
+ if BlocksOp.IsDone() == 0:
+ print "MakeHexa2Faces : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def GetPoint(theShape, theX, theY, theZ, theEpsilon):
+ """
+ * Get a vertex, found in the given shape by its coordinates.
+ * \param theShape Block or a compound of blocks.
+ * \param theX,theY,theZ Coordinates of the sought vertex.
+ * \param theEpsilon Maximum allowed distance between the resulting
+ * vertex and point with the given coordinates.
+ * \return New GEOM_Object, containing the found vertex.
+
+ * Example: see GEOM_TestOthers.py
+ """
+ anObj = BlocksOp.GetPoint(theShape, theX, theY, theZ, theEpsilon)
+ if BlocksOp.IsDone() == 0:
+ print "GetPoint : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def GetEdge(theShape, thePoint1, thePoint2):
+ """
+ * Get an edge, found in the given shape by two given vertices.
+ * \param theShape Block or a compound of blocks.
+ * \param thePoint1,thePoint2 Points, close to the ends of the desired edge.
+ * \return New GEOM_Object, containing the found edge.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.GetEdge(theShape, thePoint1, thePoint2)
+ if BlocksOp.IsDone() == 0:
+ print "GetEdge : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def GetEdgeNearPoint(theShape, thePoint):
+ """
+ * Find an edge of the given shape, which has minimal distance to the given point.
+ * \param theShape Block or a compound of blocks.
+ * \param thePoint Point, close to the desired edge.
+ * \return New GEOM_Object, containing the found edge.
+
+ * Example: see GEOM_TestOthers.py
+ """
+ anObj = BlocksOp.GetEdgeNearPoint(theShape, thePoint)
+ if BlocksOp.IsDone() == 0:
+ print "GetEdgeNearPoint : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def GetFaceByPoints(theShape, thePoint1, thePoint2, thePoint3, thePoint4):
+ """
+ * Returns a face, found in the given shape by four given corner vertices.
+ * \param theShape Block or a compound of blocks.
+ * \param thePoint1-thePoint4 Points, close to the corners of the desired face.
+ * \return New GEOM_Object, containing the found face.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.GetFaceByPoints(theShape, thePoint1, thePoint2, thePoint3, thePoint4)
+ if BlocksOp.IsDone() == 0:
+ print "GetFaceByPoints : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def GetFaceByEdges(theShape, theEdge1, theEdge2):
+ """
+ * Get a face of block, found in the given shape by two given edges.
+ * \param theShape Block or a compound of blocks.
+ * \param theEdge1,theEdge2 Edges, close to the edges of the desired face.
+ * \return New GEOM_Object, containing the found face.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.GetFaceByEdges(theShape, theEdge1, theEdge2)
+ if BlocksOp.IsDone() == 0:
+ print "GetFaceByEdges : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def GetOppositeFace(theBlock, theFace):
+ """
+ * Find a face, opposite to the given one in the given block.
+ * \param theBlock Must be a hexahedral solid.
+ * \param theFace Face of \a theBlock, opposite to the desired face.
+ * \return New GEOM_Object, containing the found face.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.GetOppositeFace(theBlock, theFace)
+ if BlocksOp.IsDone() == 0:
+ print "GetOppositeFace : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def GetFaceNearPoint(theShape, thePoint):
+ """
+ * Find a face of the given shape, which has minimal distance to the given point.
+ * \param theShape Block or a compound of blocks.
+ * \param thePoint Point, close to the desired face.
+ * \return New GEOM_Object, containing the found face.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.GetFaceNearPoint(theShape, thePoint)
+ if BlocksOp.IsDone() == 0:
+ print "GetFaceNearPoint : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def GetFaceByNormale(theBlock, theVector):
+ """
+ * Find a face of block, whose outside normale has minimal angle with the given vector.
+ * \param theShape Block or a compound of blocks.
+ * \param theVector Vector, close to the normale of the desired face.
+ * \return New GEOM_Object, containing the found face.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.GetFaceByNormale(theBlock, theVector)
+ if BlocksOp.IsDone() == 0:
+ print "GetFaceByNormale : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def CheckCompoundOfBlocks(theCompound):
+ """
+ * Check, if the compound of blocks is given.
+ * To be considered as a compound of blocks, the
+ * given shape must satisfy the following conditions:
+ * - Each element of the compound should be a Block (6 faces and 12 edges).
+ * - A connection between two Blocks should be an entire quadrangle face or an entire edge.
+ * - The compound should be connexe.
+ * - The glue between two quadrangle faces should be applied.
+ * \param theCompound The compound to check.
+ * \return TRUE, if the given shape is a compound of blocks.
+ * If theCompound is not valid, prints all discovered errors.
+
+ * Example: see GEOM_Spanner.py
+ """
+ (IsValid, BCErrors) = BlocksOp.CheckCompoundOfBlocks(theCompound)
+ if BlocksOp.IsDone() == 0:
+ print "CheckCompoundOfBlocks : ", BlocksOp.GetErrorCode()
+ else:
+ if IsValid == 0:
+ Descr = BlocksOp.PrintBCErrors(theCompound, BCErrors)
+ print Descr
+ return IsValid
+
+def RemoveExtraEdges(theShape):
+ """
+ * Remove all seam and degenerated edges from \a theShape.
+ * Unite faces and edges, sharing one surface.
+ * \param theShape The compound or single solid to remove irregular edges from.
+ * \return Improved shape.
+
+ * Example: see GEOM_TestOthers.py
+ """
+ anObj = BlocksOp.RemoveExtraEdges(theShape)
+ if BlocksOp.IsDone() == 0:
+ print "RemoveExtraEdges : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def CheckAndImprove(theShape):
+ """
+ * Check, if the given shape is a blocks compound.
+ * Fix all detected errors.
+ * \note Single block can be also fixed by this method.
+ * \param theCompound The compound to check and improve.
+ * \return Improved compound.
+
+ * Example: see GEOM_TestOthers.py
+ """
+ anObj = BlocksOp.CheckAndImprove(theShape)
+ if BlocksOp.IsDone() == 0:
+ print "CheckAndImprove : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def MakeBlockExplode(theCompound, theMinNbFaces, theMaxNbFaces):
+ """
+ * Get all the blocks, contained in the given compound.
+ * \param theCompound The compound to explode.
+ * \param theMinNbFaces If solid has lower number of faces, it is not a block.
+ * \param theMaxNbFaces If solid has higher number of faces, it is not a block.
+ * \note If theMaxNbFaces = 0, the maximum number of faces is not restricted.
+ * \return List of GEOM_Objects, containing the retrieved blocks.
+
+ * Example: see GEOM_TestOthers.py
+ """
+ aList = BlocksOp.ExplodeCompoundOfBlocks(theCompound, theMinNbFaces, theMaxNbFaces)
+ if BlocksOp.IsDone() == 0:
+ print "MakeBlockExplode : ", BlocksOp.GetErrorCode()
+ return aList
+
+def GetBlockNearPoint(theCompound, thePoint):
+ """
+ * Find block, containing the given point inside its volume or on boundary.
+ * \param theCompound Compound, to find block in.
+ * \param thePoint Point, close to the desired block. If the point lays on
+ * boundary between some blocks, we return block with nearest center.
+ * \return New GEOM_Object, containing the found block.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.GetBlockNearPoint(theCompound, thePoint)
+ if BlocksOp.IsDone() == 0:
+ print "GetBlockNearPoint : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def GetBlockByParts(theCompound, theParts):
+ """
+ * Find block, containing all the elements, passed as the parts, or maximum quantity of them.
+ * \param theCompound Compound, to find block in.
+ * \param theParts List of faces and/or edges and/or vertices to be parts of the found block.
+ * \return New GEOM_Object, containing the found block.
+
+ * Example: see GEOM_TestOthers.py
+ """
+ anObj = BlocksOp.GetBlockByParts(theCompound, theParts)
+ if BlocksOp.IsDone() == 0:
+ print "GetBlockByParts : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def GetBlocksByParts(theCompound, theParts):
+ """
+ * Return all blocks, containing all the elements, passed as the parts.
+ * \param theCompound Compound, to find blocks in.
+ * \param theParts List of faces and/or edges and/or vertices to be parts of the found blocks.
+ * \return List of GEOM_Objects, containing the found blocks.
+
+ * Example: see GEOM_Spanner.py
+ """
+ aList = BlocksOp.GetBlocksByParts(theCompound, theParts)
+ if BlocksOp.IsDone() == 0:
+ print "GetBlocksByParts : ", BlocksOp.GetErrorCode()
+ return aList
+
+def MakeMultiTransformation1D(Block, DirFace1, DirFace2, NbTimes):
+ """
+ * Multi-transformate block and glue the result.
+ * Transformation is defined so, as to superpose direction faces.
+ * \param Block Hexahedral solid to be multi-transformed.
+ * \param DirFace1 ID of First direction face.
+ * \param DirFace2 ID of Second direction face.
+ * \param NbTimes Quantity of transformations to be done.
+ * \note Unique ID of sub-shape can be obtained, using method GetSubShapeID().
+ * \return New GEOM_Object, containing the result shape.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.MakeMultiTransformation1D(Block, DirFace1, DirFace2, NbTimes)
+ if BlocksOp.IsDone() == 0:
+ print "MakeMultiTransformation1D : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def MakeMultiTransformation2D(Block, DirFace1U, DirFace2U, NbTimesU,
+ DirFace1V, DirFace2V, NbTimesV):
+ """
+ * Multi-transformate block and glue the result.
+ * \param Block Hexahedral solid to be multi-transformed.
+ * \param DirFace1U,DirFace2U IDs of Direction faces for the first transformation.
+ * \param DirFace1V,DirFace2V IDs of Direction faces for the second transformation.
+ * \param NbTimesU,NbTimesV Quantity of transformations to be done.
+ * \return New GEOM_Object, containing the result shape.
+
+ * Example: see GEOM_Spanner.py
+ """
+ anObj = BlocksOp.MakeMultiTransformation2D(Block, DirFace1U, DirFace2U, NbTimesU,
+ DirFace1V, DirFace2V, NbTimesV)
+ if BlocksOp.IsDone() == 0:
+ print "MakeMultiTransformation2D : ", BlocksOp.GetErrorCode()
+ return anObj
+
+def Propagate(theShape):
+ """
+ * 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.
+ * \param theShape Shape to build propagation groups on.
+ * \return List of GEOM_Objects, each of them is a propagation group.
+
+ * Example: see GEOM_TestOthers.py
+ """
+ listChains = BlocksOp.Propagate(theShape)
+ if BlocksOp.IsDone() == 0:
+ print "Propagate : ", BlocksOp.GetErrorCode()
+ return listChains
+
+# -----------------------------------------------------------------------------
+# Group operations