From: mpv Date: Fri, 7 Aug 2015 13:39:15 +0000 (+0300) Subject: Implementation of Partition movement using new result creation, with different data... X-Git-Tag: V_1.4.0_beta4~419 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=af44422560f41f81deca0e0911f4dd9b7c5e2ef5;p=modules%2Fshaper.git Implementation of Partition movement using new result creation, with different data. Plus some debug. --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Movement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Movement.cpp index bebbcd735..3a298e2a4 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Movement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Movement.cpp @@ -100,17 +100,7 @@ void FeaturesPlugin_Movement::execute() // Setting result. if (isPart) { ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); - - ResultPartPtr aCurrentResult; - const std::list >& aResults = results(); - std::list >::const_iterator aResIter = aResults.begin(); - for(int a = 0; aResIter != aResults.end(); aResIter++, a++) { - if (a == aResultIndex) { - aCurrentResult = std::dynamic_pointer_cast(*aResIter); - break; - } - } - ResultPartPtr aResultPart = document()->copyPart(aCurrentResult, anOrigin, aResultIndex); + ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); aResultPart->setTrsf(*aContext, aMovementAlgo.transformation()); setResult(aResultPart); } else { diff --git a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp index 69d3cc4a7..a52a2be08 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp @@ -110,8 +110,6 @@ void FeaturesPlugin_Placement::execute() bool isReverse = boolean(REVERSE_ID())->value(); bool isCentering = boolean(CENTERING_ID())->value(); - bool isPart = aContextRes->groupName() == ModelAPI_ResultPart::group(); - // Getting transformation. GeomAlgoAPI_Placement aPlacementAlgo( aStartShape, anEndShape, aStartFace, anEndFace, isReverse, isCentering, true); @@ -128,11 +126,11 @@ void FeaturesPlugin_Placement::execute() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { - if (isPart) { // for part results just set transformation - ResultPartPtr anOrigin = std::dynamic_pointer_cast(aContextRes); - ResultPartPtr aResultPart = document()->copyPart(firstResult(), anOrigin); + if ((*aContext)->groupName() == ModelAPI_ResultPart::group()) { // for part results just set transformation + ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); + ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); aResultPart->setTrsf(aContextRes, aTrsf); - setResult(aResultPart); + setResult(aResultPart, aResultIndex); } else { std::shared_ptr aBaseShape = *anObjectsIt; GeomAlgoAPI_Transform aTransformAlgo(aBaseShape, aTrsf); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp index aea860dcb..7007b9bbf 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp @@ -100,17 +100,7 @@ void FeaturesPlugin_Rotation::execute() // Setting result. if (isPart) { ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); - - ResultPartPtr aCurrentResult; - const std::list >& aResults = results(); - std::list >::const_iterator aResIter = aResults.begin(); - for(int a = 0; aResIter != aResults.end(); aResIter++, a++) { - if (a == aResultIndex) { - aCurrentResult = std::dynamic_pointer_cast(*aResIter); - break; - } - } - ResultPartPtr aResultPart = document()->copyPart(aCurrentResult, anOrigin, aResultIndex); + ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); aResultPart->setTrsf(*aContext, aRotationAlgo.transformation()); setResult(aResultPart); } else { diff --git a/src/FeaturesPlugin/placement_widget.xml b/src/FeaturesPlugin/placement_widget.xml index ec6f228b0..1989fb3a9 100644 --- a/src/FeaturesPlugin/placement_widget.xml +++ b/src/FeaturesPlugin/placement_widget.xml @@ -5,7 +5,8 @@ label="Select a solid objects" icon=":icons/cut_shape.png" tooltip="Select a solid objects" - type_choice="Solids"> + type_choice="Solids" + concealment="true" > + shape_types="face" > theSourceShape, TopLoc_Location aDelta(aTrsf); aResult = aSourceShape.Moved(aDelta); // store the accumulated information about the result and this delta - myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation()))); + //myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation()))); + myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf))); myDone = true; // is OK for sure } else { BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp index 6e28fc603..4e29cdb30 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp @@ -195,7 +195,8 @@ void GeomAlgoAPI_Placement::build( TopoDS_Shape aResult = aSourceShape.Moved(aDelta); myShape->setImpl(new TopoDS_Shape(aResult)); // store the accumulated information about the result and this delta - myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation()))); + //myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation()))); + myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf))); myDone = true; // it is allways true for simple transformation generation } else { // internal rebuild of the shape // Transform the shape with copying it diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp index 1d1d84959..17c88e408 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp @@ -51,7 +51,8 @@ void GeomAlgoAPI_Rotation::build(std::shared_ptr theSourceShape, if (theSimpleTransform) { TopLoc_Location aDelta(aTrsf); aResult = aSourceShape.Moved(aDelta); - myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation()))); + //myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation()))); + myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf))); myDone = true; // is OK for sure } else { BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true); diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index b160e3752..2ff8141aa 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -813,11 +813,10 @@ std::shared_ptr Model_Document::createPart( } std::shared_ptr Model_Document::copyPart( - const std::shared_ptr& theOldPart, - const std::shared_ptr& theOrigin, - const int theIndex) + const std::shared_ptr& theOrigin, + const std::shared_ptr& theFeatureData, const int theIndex) { - return myObjs->copyPart(theOldPart, theOrigin, theIndex); + return myObjs->copyPart(theOrigin, theFeatureData, theIndex); } std::shared_ptr Model_Document::createGroup( diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 626e2f4b2..3b7da9790 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -157,11 +157,10 @@ class Model_Document : public ModelAPI_Document /// Creates a part results MODEL_EXPORT virtual std::shared_ptr createPart( const std::shared_ptr& theFeatureData, const int theIndex = 0); - //! Copies a part result, keeping the same data + //! Copies a part result, keeping the reference to origin MODEL_EXPORT virtual std::shared_ptr copyPart( - const std::shared_ptr& theOldPart, - const std::shared_ptr& theOrigin, - const int theIndex = 0); + const std::shared_ptr& theOrigin, + const std::shared_ptr& theFeatureData, const int theIndex = 0); /// Creates a group results MODEL_EXPORT virtual std::shared_ptr createGroup( const std::shared_ptr& theFeatureData, const int theIndex = 0); diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index bec876498..9e4e270ac 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -799,18 +799,11 @@ std::shared_ptr Model_Objects::createPart( } std::shared_ptr Model_Objects::copyPart( - const std::shared_ptr& theOldPart, - const std::shared_ptr& theOrigin, const int theIndex) + const std::shared_ptr& theOrigin, + const std::shared_ptr& theFeatureData, const int theIndex) { - std::shared_ptr aResult; - if (theOldPart.get()) { - aResult = std::dynamic_pointer_cast(theOldPart); - } - if (!aResult) { - aResult = std::shared_ptr(new Model_ResultPart); - aResult->setDoc(myDoc); - aResult->setData(theOrigin->data()); - } + std::shared_ptr aResult = createPart(theFeatureData, theIndex); + aResult->data()->reference(Model_ResultPart::BASE_REF_ID())->setValue(theOrigin); return aResult; } diff --git a/src/Model/Model_Objects.h b/src/Model/Model_Objects.h index bf6904715..45c837d62 100644 --- a/src/Model/Model_Objects.h +++ b/src/Model/Model_Objects.h @@ -106,10 +106,10 @@ class Model_Objects /// Creates a part results std::shared_ptr createPart( const std::shared_ptr& theFeatureData, const int theIndex = 0); - /// Copies a part results, keeping the same data + /// Copies a part results, keeping the reference to origin std::shared_ptr copyPart( - const std::shared_ptr& theOldPart, - const std::shared_ptr& theOrigin, const int theIndex = 0); + const std::shared_ptr& theOrigin, + const std::shared_ptr& theFeatureData, const int theIndex = 0); /// Creates a group results std::shared_ptr createGroup( const std::shared_ptr& theFeatureData, const int theIndex = 0); diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index 96957848a..246621acd 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -25,23 +26,24 @@ #include #include +#define baseRef() std::dynamic_pointer_cast(data()->reference(BASE_REF_ID())->value()) + void Model_ResultPart::initAttributes() { // append the color attribute. It is empty, the attribute will be filled by a request data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::typeId()); data()->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId()); + data()->addAttribute(BASE_REF_ID(), ModelAPI_AttributeReference::typeId()); } std::shared_ptr Model_ResultPart::partDoc() { + if (myTrsf.get()) { + return baseRef()->partDoc(); + } return data()->document("PartDocument")->value(); } -std::shared_ptr Model_ResultPart::owner() -{ - return std::shared_ptr(); // return empty pointer -} - Model_ResultPart::Model_ResultPart() { myIsDisabled = true; // by default it is not initialized and false to be after created @@ -50,6 +52,11 @@ Model_ResultPart::Model_ResultPart() void Model_ResultPart::activate() { + if (myTrsf.get()) { + baseRef()->activate(); + return; + } + std::shared_ptr aDocRef = data()->document(DOC_REF()); if (!aDocRef->value().get()) { // create (or open) a document if it is not yet created @@ -74,6 +81,10 @@ void Model_ResultPart::activate() bool Model_ResultPart::isActivated() { + if (myTrsf.get()) { + return baseRef()->isActivated(); + } + std::shared_ptr aDocRef = data()->document(DOC_REF()); return aDocRef->value().get() != NULL; } @@ -106,8 +117,7 @@ std::shared_ptr Model_ResultPart::shape() { std::shared_ptr aResult(new GeomAPI_Shape); if (myTrsf.get()) { // get shape of the base result and apply the transformation - ResultPtr anOrigResult = - std::dynamic_pointer_cast(data()->attribute(COLOR_ID())->owner()); + ResultPtr anOrigResult = baseRef(); std::shared_ptr anOrigShape = anOrigResult->shape(); if (anOrigShape.get()) { TopoDS_Shape aShape = anOrigShape->impl(); @@ -165,8 +175,7 @@ std::string Model_ResultPart::nameInPart(const std::shared_ptr& t theIndex = 0; // not initialized if (myTrsf.get()) { // if this is moved copy of part => return the name of original shape - ResultPartPtr anOrigResult = - std::dynamic_pointer_cast(data()->attribute(COLOR_ID())->owner()); + ResultPartPtr anOrigResult = baseRef(); // searching in the origin the shape equal to the given but with myTrsf TopoDS_Shape aSelection = theShape->impl(); gp_Trsf aSelTrsf = aSelection.Location().Transformation(); diff --git a/src/Model/Model_ResultPart.h b/src/Model/Model_ResultPart.h index a04e0024f..fee8e0ad1 100644 --- a/src/Model/Model_ResultPart.h +++ b/src/Model/Model_ResultPart.h @@ -24,12 +24,17 @@ class Model_ResultPart : public ModelAPI_ResultPart TopoDS_Shape myShape; ///< shape of this part created from bodies (updated only of Part deactivation) std::shared_ptr myTrsf; ///< if it is just copy of original shape, keep just transformation public: + + /// the reference to the base result document, may be null if this is the root, others make sequence of references + inline static const std::string& BASE_REF_ID() + { + static const std::string MY_BASE_REF("BaseReference"); + return MY_BASE_REF; + } /// Request for initialization of data model of the result: adding all attributes virtual void initAttributes(); /// Returns the part-document of this result MODEL_EXPORT virtual std::shared_ptr partDoc(); - /// Part has no stored feature: this method returns NULL - MODEL_EXPORT virtual std::shared_ptr owner(); /// Sets this document as current and if it is not loaded yet, loads it MODEL_EXPORT virtual void activate(); diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index 692cc0881..46efe12ab 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -10,6 +10,7 @@ %{ #include "ModelAPI.h" + #include "ModelAPI_Entity.h" #include "ModelAPI_Document.h" #include "ModelAPI_Session.h" #include "ModelAPI_Object.h" @@ -69,6 +70,7 @@ // shared pointers // For ModelAPI_ResultConstruction.shape() +%shared_ptr(ModelAPI_Entity) %shared_ptr(ModelAPI_Document) %shared_ptr(ModelAPI_Session) %shared_ptr(ModelAPI_Plugin) @@ -98,6 +100,7 @@ %shared_ptr(ModelAPI_ResultParameter) // all supported interfaces +%include "ModelAPI_Entity.h" %include "ModelAPI_Document.h" %include "ModelAPI_Session.h" %include "ModelAPI_Plugin.h" diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 9557a0851..c05f5c7fe 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -130,11 +130,10 @@ public: //! Creates a part results virtual std::shared_ptr createPart( const std::shared_ptr& theFeatureData, const int theIndex = 0) = 0; - //! Copies a part result, keeping the same data + //! Copies a part result, keeping the reference to the origin virtual std::shared_ptr copyPart( - const std::shared_ptr& theOldPart, - const std::shared_ptr& theOrigin, - const int theIndex = 0) = 0; + const std::shared_ptr& theOrigin, + const std::shared_ptr& theFeatureData, const int theIndex = 0) = 0; //! Creates a group results virtual std::shared_ptr createGroup( const std::shared_ptr& theFeatureData, const int theIndex = 0) = 0; diff --git a/src/XGUI/XGUI_ErrorMgr.cpp b/src/XGUI/XGUI_ErrorMgr.cpp index f46a9291e..9dda1abbb 100644 --- a/src/XGUI/XGUI_ErrorMgr.cpp +++ b/src/XGUI/XGUI_ErrorMgr.cpp @@ -53,7 +53,7 @@ void XGUI_ErrorMgr::onValidationStateChanged() // get feature FeaturePtr aFeature = anOperationMgr->currentOperation()->feature(); - if (!aFeature.get()) + if (!aFeature.get() || !aFeature->data()->isValid()) return; // set error indication