From 3dff858d0d0d7799e68a9e123c86c5dc77c62622 Mon Sep 17 00:00:00 2001 From: skv Date: Thu, 16 Oct 2014 18:31:50 +0400 Subject: [PATCH] Implement TUI --- .../examples/topological_geom_objs_ex03.py | 5 ++ idl/GEOM_Gen.idl | 9 +++ src/GEOMImpl/GEOMImpl_IShapesOperations.cxx | 71 +++++++++++++++++++ src/GEOMImpl/GEOMImpl_IShapesOperations.hxx | 4 ++ src/GEOMImpl/GEOMImpl_ShapeDriver.cxx | 58 +++++++++++++++ src/GEOMImpl/GEOMImpl_Types.hxx | 1 + src/GEOM_I/GEOM_IShapesOperations_i.cc | 33 +++++++++ src/GEOM_I/GEOM_IShapesOperations_i.hh | 3 + src/GEOM_SWIG/GEOM_TestAll.py | 2 + src/GEOM_SWIG/geomBuilder.py | 33 +++++++++ 10 files changed, 219 insertions(+) mode change 100755 => 100644 src/GEOMImpl/GEOMImpl_Types.hxx diff --git a/doc/salome/examples/topological_geom_objs_ex03.py b/doc/salome/examples/topological_geom_objs_ex03.py index db2f060a9..972d81a6f 100644 --- a/doc/salome/examples/topological_geom_objs_ex03.py +++ b/doc/salome/examples/topological_geom_objs_ex03.py @@ -36,11 +36,13 @@ face1 = geompy.MakeFace(wire, isPlanarFace) # create faces from two wires face2 = geompy.MakeFaceWires([wire, sketcher1],isPlanarFace) face3 = geompy.MakeFaces([sketcher2, sketcher3],isPlanarFace) +face4 = geompy.MakeFaceFromSurface(face1, sketcher1) # add objects in the study id_face1 = geompy.addToStudy(face1,"Face1") id_face2 = geompy.addToStudy(face2,"Face2") id_face3 = geompy.addToStudy(face3,"Face3") +id_face4 = geompy.addToStudy(face4,"Face4") # display the faces gg.createAndDisplayGO(id_face1) @@ -52,3 +54,6 @@ gg.setTransparency(id_face2,0.2) gg.createAndDisplayGO(id_face3) gg.setDisplayMode(id_face3,1) gg.setTransparency(id_face3,0.2) +gg.createAndDisplayGO(id_face4) +gg.setDisplayMode(id_face4,1) +gg.setTransparency(id_face4,0.2) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 7679626b7..6cfdd8a28 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -1924,6 +1924,15 @@ module GEOM */ GEOM_Object MakeFaceWires (in ListOfGO theWires, in boolean isPlanarWanted); + /** + * \brief Create a face based on surface of theFace limited by theWire. + * \param theFace the face whose surface is used to create a new face. + * \param theWire closed Wire build the face. + * \return New GEOM_Object, containing the created face. + */ + GEOM_Object MakeFaceFromSurface(in GEOM_Object theFace, + in GEOM_Object theWire); + /*! * \brief Create a shell from the set of faces and shells. * \param theFacesAndShells List of faces and/or shells. diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx index c0613097d..cf840bc75 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx @@ -548,6 +548,77 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFaceWires return aShape; } +//============================================================================= +/*! + * MakeFaceFromSurface + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFaceFromSurface + (Handle(GEOM_Object) theFace, + Handle(GEOM_Object) theWire) +{ + SetErrorCode(KO); + + //Add a new object + Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_FACE); + + //Add a new function + Handle(GEOM_Function) aFunction = + aShape->AddFunction(GEOMImpl_ShapeDriver::GetID(), FACE_FROM_SURFACE); + + if (aFunction.IsNull()) { + return NULL; + } + + //Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) { + return NULL; + } + + GEOMImpl_IShapes aCI (aFunction); + Handle(TColStd_HSequenceOfTransient) aShapesSeq = + new TColStd_HSequenceOfTransient; + Handle(GEOM_Function) aRefFace = theFace->GetLastFunction(); + Handle(GEOM_Function) aRefWire = theWire->GetLastFunction(); + + if (aRefFace.IsNull()) { + SetErrorCode("NULL argument face for the face construction"); + return NULL; + } + + if (aRefWire.IsNull()) { + SetErrorCode("NULL argument wire for the face construction"); + return NULL; + } + + aShapesSeq->Append(aRefFace); + aShapesSeq->Append(aRefWire); + + aCI.SetShapes(aShapesSeq); + + //Compute the face + try { + OCC_CATCH_SIGNALS; + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Shape driver failed"); + return NULL; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return NULL; + } + + //Make a Python command + GEOM::TPythonDump (aFunction) << aShape + << " = geompy.MakeFaceFromSurface(" << theFace << ", " << theWire << ")"; + + SetErrorCode(OK); + + return aShape; +} + //============================================================================= /*! * MakeShell diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx index a5b6bc396..8c15f7190 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx @@ -85,6 +85,10 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations Standard_EXPORT Handle(GEOM_Object) MakeFaceWires (std::list theWires, const bool isPlanarWanted); + Standard_EXPORT Handle(GEOM_Object) MakeFaceFromSurface + (Handle(GEOM_Object) theFace, + Handle(GEOM_Object) theWire); + Standard_EXPORT Handle(GEOM_Object) MakeShell (std::list theShapes); Standard_EXPORT Handle(GEOM_Object) MakeSolidShells (std::list theShells); diff --git a/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx b/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx index 037e62900..d09b3a329 100644 --- a/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -315,6 +316,44 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const aShape = C; } } + else if (aType == FACE_FROM_SURFACE) { +#ifdef RESULT_TYPE_CHECK + anExpectedType = TopAbs_FACE; +#endif + + Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes(); + + if (aShapes.IsNull() == Standard_False) { + Standard_Integer aNbShapes = aShapes->Length(); + + if (aNbShapes == 2) { + Handle(GEOM_Function) aRefFace = + Handle(GEOM_Function)::DownCast(aShapes->Value(1)); + Handle(GEOM_Function) aRefWire = + Handle(GEOM_Function)::DownCast(aShapes->Value(2)); + + if (aRefFace.IsNull() == Standard_False && + aRefWire.IsNull() == Standard_False) { + TopoDS_Shape aShFace = aRefFace->GetValue(); + TopoDS_Shape aShWire = aRefWire->GetValue(); + + if (aShFace.IsNull() == Standard_False && + aShFace.ShapeType() == TopAbs_FACE && + aShWire.IsNull() == Standard_False && + aShWire.ShapeType() == TopAbs_WIRE) { + TopoDS_Face aFace = TopoDS::Face(aShFace); + TopoDS_Wire aWire = TopoDS::Wire(aShWire); + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); + BRepBuilderAPI_MakeFace aMkFace(aSurf, aWire); + + if (aMkFace.IsDone()) { + aShape = aMkFace.Shape(); + } + } + } + } + } + } else if (aType == SHELL_FACES) { #ifdef RESULT_TYPE_CHECK anExpectedType = TopAbs_SHELL; @@ -1268,6 +1307,25 @@ GetCreationInformation(std::string& theOperationName, AddParam( theParams, "Wires/edges", aCI.GetShapes() ); AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() ); break; + case FACE_FROM_SURFACE: + { + theOperationName = "FACE"; + + Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes(); + + if (shapes.IsNull() == Standard_False) { + Standard_Integer aNbShapes = shapes->Length(); + + if (aNbShapes > 0) { + AddParam(theParams, "Face", shapes->Value(1)); + + if (aNbShapes > 1) { + AddParam(theParams, "Wire", shapes->Value(2)); + } + } + } + break; + } case SHELL_FACES: theOperationName = "SHELL"; AddParam( theParams, "Objects", aCI.GetShapes() ); diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx old mode 100755 new mode 100644 index 0bc7505c1..419e10160 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -299,6 +299,7 @@ #define EDGE_CURVE_LENGTH 12 #define SHAPES_ON_SHAPE 13 #define SHAPE_ISOLINE 14 +#define FACE_FROM_SURFACE 15 #define ARCHIMEDE_TYPE 1 diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.cc b/src/GEOM_I/GEOM_IShapesOperations_i.cc index 1e965a798..a03d84e47 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.cc +++ b/src/GEOM_I/GEOM_IShapesOperations_i.cc @@ -246,6 +246,39 @@ GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFaceWires return GetObject(anObject); } +//============================================================================= +/*! + * MakeFaceFromSurface + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFaceFromSurface + (GEOM::GEOM_Object_ptr theFace, + GEOM::GEOM_Object_ptr theWire) +{ + GEOM::GEOM_Object_var aGEOMObject; + + //Set a not done flag + GetOperations()->SetNotDone(); + + //Get the reference face and wire + Handle(GEOM_Object) aFace = GetObjectImpl(theFace); + Handle(GEOM_Object) aWire = GetObjectImpl(theWire); + + if (aFace.IsNull() || aWire.IsNull()) { + return aGEOMObject._retn(); + } + + //Create the Face + Handle(GEOM_Object) anObject = + GetOperations()->MakeFaceFromSurface(aFace, aWire); + + if (anObject.IsNull()) { + return aGEOMObject._retn(); + } + + return GetObject(anObject); +} + //============================================================================= /*! * MakeShell diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.hh b/src/GEOM_I/GEOM_IShapesOperations_i.hh index 8b18fe9f2..be9d5584c 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.hh +++ b/src/GEOM_I/GEOM_IShapesOperations_i.hh @@ -64,6 +64,9 @@ class GEOM_I_EXPORT GEOM_IShapesOperations_i : GEOM::GEOM_Object_ptr MakeFaceWires (const GEOM::ListOfGO& theWires, CORBA::Boolean isPlanarWanted); + GEOM::GEOM_Object_ptr MakeFaceFromSurface(GEOM::GEOM_Object_ptr theFace, + GEOM::GEOM_Object_ptr theWire); + GEOM::GEOM_Object_ptr MakeShell (const GEOM::ListOfGO& theFacesAndShells); GEOM::GEOM_Object_ptr MakeSolidShell (GEOM::GEOM_Object_ptr theShell); diff --git a/src/GEOM_SWIG/GEOM_TestAll.py b/src/GEOM_SWIG/GEOM_TestAll.py index b644c196b..a63590d52 100644 --- a/src/GEOM_SWIG/GEOM_TestAll.py +++ b/src/GEOM_SWIG/GEOM_TestAll.py @@ -178,6 +178,7 @@ def TestAll (geompy, math): Face2 = geompy.MakeFace(Sketcher, WantPlanarFace) Face3 = geompy.MakeFaceHW (100., 200., 1) #(2 Doubles, 1 Int)->GEOM_Object Face4 = geompy.MakeFaceObjHW (vz, 200., 100.) #(1 GEOM_Object, 2 Doubles)->GEOM_Object + Face5 = geompy.MakeFaceFromSurface(Face, Sketcher) #(2 GEOM_Objects)->GEOM_Object Disk = geompy.MakeDiskPntVecR (p0, vz, radius) #(2 GEOM_Object, 1 Double)->GEOM_Object Disk2 = geompy.MakeDiskThreePnt(p0, p200, pz) #(3 GEOM_Object)->GEOM_Object Disk3 = geompy.MakeDiskR(100., 1) #(1 Doubles, 1 Int)->GEOM_Object @@ -397,6 +398,7 @@ def TestAll (geompy, math): id_Face2 = geompy.addToStudy(Face2, "Face from Sketcher") id_Face3 = geompy.addToStudy(Face3, "Face Height Width") id_Face4 = geompy.addToStudy(Face4, "Face Plane_HW") + id_Face5 = geompy.addToStudy(Face5, "Face from surface and wire") id_Disk = geompy.addToStudy(Disk, "Disk PntVecR") id_Disk2 = geompy.addToStudy(Disk2, "Disk Three Points") id_Disk3 = geompy.addToStudy(Disk3, "Disk OXY Radius") diff --git a/src/GEOM_SWIG/geomBuilder.py b/src/GEOM_SWIG/geomBuilder.py index 976f9e9fb..d289705a1 100644 --- a/src/GEOM_SWIG/geomBuilder.py +++ b/src/GEOM_SWIG/geomBuilder.py @@ -4504,6 +4504,39 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen): anObj = self.MakeFaceWires(theWires, isPlanarWanted, theName) return anObj + ## Create a face based on a surface from given face bounded + # by given wire. + # @param theFace the face whose surface is used to create a new face. + # @param theWire the wire that will bound a new face. + # @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 created face. + # + # @ref tui_creation_face "Example" + @ManageTransactions("ShapesOp") + def MakeFaceFromSurface(self, theFace, theWire, theName=None): + """ + Create a face based on a surface from given face bounded + by given wire. + + Parameters: + theFace the face whose surface is used to create a new face. + theWire the wire that will bound a new face. + 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 created face. + """ + # Example: see GEOM_TestAll.py + anObj = self.ShapesOp.MakeFaceFromSurface(theFace, theWire) + RaiseIfFailed("MakeFaceFromSurface", self.ShapesOp) + self._autoPublish(anObj, theName, "face") + return anObj + ## Create a shell from the set of faces and shells. # @param theFacesAndShells List of faces and/or shells. # @param theName Object name; when specified, this parameter is used -- 2.39.2