From: spo Date: Tue, 14 Jun 2016 12:12:45 +0000 (+0300) Subject: Add resilt() and selectFace() X-Git-Tag: V_2.4.0~91^2~53 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8631b1948e52fd933156530dcc5785fd1ed6e05f;p=modules%2Fshaper.git Add resilt() and selectFace() --- diff --git a/src/ModelHighAPI/ModelHighAPI.i b/src/ModelHighAPI/ModelHighAPI.i index 522ed48de..7bea7bc27 100644 --- a/src/ModelHighAPI/ModelHighAPI.i +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -3,6 +3,9 @@ %{ #include "ModelHighAPI_swig.h" + + // fix for SWIG v2.0.4 + #define SWIGPY_SLICE_ARG(obj) ((PySliceObject*)(obj)) %} %include "doxyhelp.i" @@ -112,3 +115,5 @@ %include "ModelHighAPI_RefAttr.h" %include "ModelHighAPI_Selection.h" %include "ModelHighAPI_Tools.h" + +%template(SelectionList) std::list; diff --git a/src/ModelHighAPI/ModelHighAPI_Interface.cpp b/src/ModelHighAPI/ModelHighAPI_Interface.cpp index 7e6c41d25..caa3d7ace 100644 --- a/src/ModelHighAPI/ModelHighAPI_Interface.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Interface.cpp @@ -10,6 +10,8 @@ #include #include + +#include "ModelHighAPI_Selection.h" //-------------------------------------------------------------------------------------- ModelHighAPI_Interface::ModelHighAPI_Interface(const std::shared_ptr & theFeature) : myFeature(theFeature) @@ -38,6 +40,18 @@ void ModelHighAPI_Interface::execute() feature()->execute(); } +std::list ModelHighAPI_Interface::result() const +{ + std::list aSelectionList; + + std::list > aResults = feature()->results(); + for (auto it = aResults.begin(), end = aResults.end(); it != end; ++it) { + aSelectionList.push_back(ModelHighAPI_Selection(*it)); + } + + return aSelectionList; +} + void ModelHighAPI_Interface::throwException(const std::string & theDescription) { Events_Error::send(theDescription); diff --git a/src/ModelHighAPI/ModelHighAPI_Interface.h b/src/ModelHighAPI/ModelHighAPI_Interface.h index 8298e9bad..fd536ca33 100644 --- a/src/ModelHighAPI/ModelHighAPI_Interface.h +++ b/src/ModelHighAPI/ModelHighAPI_Interface.h @@ -10,10 +10,12 @@ //-------------------------------------------------------------------------------------- #include "ModelHighAPI.h" +#include #include #include //-------------------------------------------------------------------------------------- class ModelAPI_Feature; +class ModelHighAPI_Selection; //-------------------------------------------------------------------------------------- /**\class ModelHighAPI_Interface * \ingroup CPPHighAPI @@ -41,6 +43,10 @@ public: MODELHIGHAPI_EXPORT void execute(); + /// Return all objects of the feature + MODELHIGHAPI_EXPORT + virtual std::list result() const; + /// Throw exception to event loop MODELHIGHAPI_EXPORT void throwException(const std::string & theDescription); diff --git a/src/PythonAPI/examples/MakeBrick1.py b/src/PythonAPI/examples/MakeBrick1.py index ba828e87f..1d4461813 100644 --- a/src/PythonAPI/examples/MakeBrick1.py +++ b/src/PythonAPI/examples/MakeBrick1.py @@ -30,13 +30,15 @@ mybase.setCoincident(l2.endPoint(), l3.startPoint()) mybase.setCoincident(l3.endPoint(), l4.startPoint()) mybase.setCoincident(l4.endPoint(), l1.startPoint()) -mybase.setParallel(l1.result(), l3.result()) -mybase.setParallel(l2.result(), l4.result()) +mybase.setParallel(l1, l3) +mybase.setParallel(l2, l4) -mybase.setPerpendicular(l1.result(), l4.result()) +mybase.setPerpendicular(l1, l4) -mywidth = mybase.setLength(l1.result(), 50) -mylength = mybase.setDistance(l1.startPoint(), l3.result(), 50) +mywidth = mybase.setLength(l1, 50) +mylength = mybase.setDistance(l1.startPoint(), l3, 50) + +mybase.execute() # Creating the extrusion @@ -53,14 +55,14 @@ thiszmax = "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/To_Face_1_1" mystand = model.addSketch(mypart, thisface) c1 = mystand.addCircle(0, 25, 5) -mystand.setDistance(c1.center(), thisxmin, 10) -mystand.setDistance(c1.center(), thiszmax, 10) +mystand.setDistance(c1.center(), mystand.addLine(thisxmin), 10) +mystand.setDistance(c1.center(), mystand.addLine(thiszmax), 10) -myboss = model.addExtrusion(mypart, mystand.selectFace(c1.result()), -5) +myboss = model.addExtrusion(mypart, mystand.selectFace(), -5) # Subtracting the cylinder to the box -model.addSubtraction(mypart, mybox.result(), myboss.result()) +model.addCut(mypart, mybox.result(), myboss.result()) model.end() diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index 52119f62b..e478339f2 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -26,6 +26,7 @@ #include //-------------------------------------------------------------------------------------- #include +#include #include #include #include @@ -99,6 +100,25 @@ void SketchAPI_Sketch::setValue( theConstraint->execute(); } +//-------------------------------------------------------------------------------------- +std::list SketchAPI_Sketch::selectFace() const +{ + std::list aSelectionList; + + ResultConstructionPtr aResultConstruction = + std::dynamic_pointer_cast(feature()->firstResult()); + if (aResultConstruction.get() == NULL) + return aSelectionList; + + for (int anIndex = 0; anIndex < aResultConstruction->facesNum(); ++anIndex) { + aSelectionList.push_back( + ModelHighAPI_Selection(aResultConstruction, + aResultConstruction->face(anIndex))); + } + + return aSelectionList; +} + //-------------------------------------------------------------------------------------- SketchPtr addSketch(const std::shared_ptr & thePart, const std::shared_ptr & thePlane) diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index 70ec19cb9..fdbaca992 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -10,6 +10,8 @@ //-------------------------------------------------------------------------------------- #include "SketchAPI.h" +#include + #include #include @@ -155,6 +157,11 @@ public: // TODO(spo): setText. Is it necessary as setValue accepts text expressions? + // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG) + /// Select face + SKETCHAPI_EXPORT + std::list selectFace() const; + protected: std::shared_ptr compositeFeature() const;