From 69c8d7e9b1bbea1be3339f80ae3d01611b6aaf4b Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 11 Jul 2014 12:37:48 +0400 Subject: [PATCH] Working with Construction results in SketchPlugin --- src/Model/Model_Document.cpp | 34 +++++++++---------- src/Model/Model_Document.h | 2 +- src/Model/Model_ResultConstruction.cpp | 7 ++-- src/Model/Model_ResultConstruction.h | 2 +- src/Model/Model_Update.cpp | 4 +-- src/ModelAPI/ModelAPI_Document.h | 12 ------- src/ModelAPI/ModelAPI_Feature.h | 7 ++++ src/ModelAPI/ModelAPI_ResultBody.h | 2 +- src/SketchPlugin/SketchPlugin_Arc.h | 10 ++---- src/SketchPlugin/SketchPlugin_Circle.cpp | 6 ++-- src/SketchPlugin/SketchPlugin_Circle.h | 10 +++--- .../SketchPlugin_ConstraintCoincidence.cpp | 2 +- .../SketchPlugin_ConstraintCoincidence.h | 2 +- .../SketchPlugin_ConstraintDistance.cpp | 2 +- .../SketchPlugin_ConstraintDistance.h | 2 +- .../SketchPlugin_ConstraintLength.cpp | 2 +- .../SketchPlugin_ConstraintLength.h | 2 +- .../SketchPlugin_ConstraintParallel.cpp | 12 +++++-- .../SketchPlugin_ConstraintParallel.h | 5 +-- .../SketchPlugin_ConstraintPerpendicular.cpp | 12 +++++-- .../SketchPlugin_ConstraintPerpendicular.h | 5 +-- .../SketchPlugin_ConstraintRadius.cpp | 2 +- .../SketchPlugin_ConstraintRadius.h | 2 +- src/SketchPlugin/SketchPlugin_Feature.cpp | 13 ++++--- src/SketchPlugin/SketchPlugin_Feature.h | 9 ++--- src/SketchPlugin/SketchPlugin_Line.cpp | 6 ++-- src/SketchPlugin/SketchPlugin_Line.h | 10 ++---- src/SketchPlugin/SketchPlugin_Point.cpp | 6 ++-- src/SketchPlugin/SketchPlugin_Point.h | 12 +++---- src/SketchPlugin/SketchPlugin_Sketch.cpp | 20 ++++++----- src/SketchPlugin/SketchPlugin_Sketch.h | 6 +--- 31 files changed, 113 insertions(+), 115 deletions(-) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 68ec29401..d94957494 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -351,12 +351,12 @@ FeaturePtr Model_Document::addFeature(string theID) if (aFeature) { TDF_Label aFeatureLab; if (!aFeature->isAction()) {// do not add action to the data model - TDF_Label aFeaturesLab = groupLabel(FEATURES_GROUP); + TDF_Label aFeaturesLab = groupLabel(ModelAPI_Feature::group()); aFeatureLab = aFeaturesLab.NewChild(); initData(aFeature, aFeatureLab, TAG_FEATURE_ARGUMENTS); // keep the feature ID to restore document later correctly TDataStd_Comment::Set(aFeatureLab, aFeature->getKind().c_str()); - myObjs[FEATURES_GROUP].push_back(aFeature); + myObjs[ModelAPI_Feature::group()].push_back(aFeature); // store feature in the history of features array if (aFeature->isInHistory()) { AddToRefArray(aFeaturesLab, aFeatureLab); @@ -372,10 +372,10 @@ FeaturePtr Model_Document::addFeature(string theID) return aFeature; } -void Model_Document::storeResult(boost::shared_ptr theResult, - const int theResultIndex) +void Model_Document::storeResult(boost::shared_ptr theFeature, + boost::shared_ptr theResult, const int theResultIndex) { - initData(theResult, boost::dynamic_pointer_cast(theResult->owner()->data())-> + initData(theResult, boost::dynamic_pointer_cast(theFeature->data())-> label().Father().FindChild(TAG_FEATURE_RESULTS), theResultIndex); } @@ -415,7 +415,7 @@ void Model_Document::removeFeature(FeaturePtr theFeature) boost::shared_ptr aData = boost::static_pointer_cast(theFeature->data()); TDF_Label aFeatureLabel = aData->label().Father(); // remove feature from the myObjects list - std::vector& aVec = myObjs[FEATURES_GROUP]; + std::vector& aVec = myObjs[ModelAPI_Feature::group()]; std::vector::iterator anIter = aVec.begin(); while(anIter != aVec.end()) { if (*anIter == theFeature) { @@ -427,10 +427,10 @@ void Model_Document::removeFeature(FeaturePtr theFeature) // erase all attributes under the label of feature aFeatureLabel.ForgetAllAttributes(); // remove it from the references array - RemoveFromRefArray(groupLabel(FEATURES_GROUP), aData->label()); + RemoveFromRefArray(groupLabel(ModelAPI_Feature::group()), aData->label()); // event: feature is deleted - ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), FEATURES_GROUP); + ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group()); } /// returns the object group name by the object label @@ -445,7 +445,7 @@ static string groupName(TDF_Label theObjectLabel) { FeaturePtr Model_Document::feature(TDF_Label& theLabel) { // iterate all features, may be optimized later by keeping labels-map - std::vector& aVec = myObjs[FEATURES_GROUP]; + std::vector& aVec = myObjs[ModelAPI_Feature::group()]; vector::iterator aFIter = aVec.begin(); for(; aFIter != aVec.end(); aFIter++) { boost::shared_ptr aData = @@ -466,7 +466,7 @@ boost::shared_ptr Model_Document::subDocument(string theDocID ObjectPtr Model_Document::object(const string& theGroupID, const int theIndex) { - if (theGroupID == FEATURES_GROUP) { + if (theGroupID == ModelAPI_Feature::group()) { std::map >::iterator aFind = myObjs.find(theGroupID); if (aFind != myObjs.end()) { int aSize = aFind->second.size(); @@ -475,7 +475,7 @@ ObjectPtr Model_Document::object(const string& theGroupID, const int theIndex) } } else { // iterate all features in order to find the needed result - std::map >::iterator aFind = myObjs.find(FEATURES_GROUP); + std::map >::iterator aFind = myObjs.find(ModelAPI_Feature::group()); if (aFind != myObjs.end()) { vector::iterator aFIter = aFind->second.begin(); for(int anIndex = 0; aFIter != aFind->second.end(); aFIter++) { @@ -499,14 +499,14 @@ ObjectPtr Model_Document::object(const string& theGroupID, const int theIndex) int Model_Document::size(const string& theGroupID) { int aResult = 0; - if (theGroupID == FEATURES_GROUP) { + if (theGroupID == ModelAPI_Feature::group()) { std::map >::iterator aFind = myObjs.find(theGroupID); if (aFind != myObjs.end()) { aResult = aFind->second.size(); } } else { // iterate all features in order to find the needed result - std::map >::iterator aFind = myObjs.find(FEATURES_GROUP); + std::map >::iterator aFind = myObjs.find(ModelAPI_Feature::group()); if (aFind != myObjs.end()) { vector::iterator aFIter = aFind->second.begin(); for(; aFIter != aFind->second.end(); aFIter++) { @@ -560,9 +560,9 @@ void Model_Document::setUniqueName(FeaturePtr theFeature) string aName; // result // first count all objects of such kind to start with index = count + 1 int a, aNumObjects = 0; - int aSize = size(FEATURES_GROUP); + int aSize = size(ModelAPI_Feature::group()); for(a = 0; a < aSize; a++) { - if (boost::dynamic_pointer_cast(object(FEATURES_GROUP, a))->getKind() + if (boost::dynamic_pointer_cast(object(ModelAPI_Feature::group(), a))->getKind() == theFeature->getKind()) aNumObjects++; } @@ -572,7 +572,7 @@ void Model_Document::setUniqueName(FeaturePtr theFeature) aName = aNameStream.str(); // check this is unique, if not, increase index by 1 for(a = 0; a < aSize;) { - if (boost::dynamic_pointer_cast(object(FEATURES_GROUP, a)) + if (boost::dynamic_pointer_cast(object(ModelAPI_Feature::group(), a)) ->data()->name() == aName) { aNumObjects++; stringstream aNameStream; @@ -670,7 +670,7 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated) setCheckTransactions(true); } -boost::shared_ptr createConstruction() +boost::shared_ptr Model_Document::createConstruction() { boost::shared_ptr aResult(new Model_ResultConstruction()); return aResult; diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index f6d59b785..ec69667b7 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -88,7 +88,7 @@ public: MODEL_EXPORT virtual int size(const std::string& theGroupID); //! Allows to store the result in the data tree of the document (attaches 'data' of result to tree) - MODEL_EXPORT virtual void storeResult( + MODEL_EXPORT virtual void storeResult(boost::shared_ptr theFeature, boost::shared_ptr theResult, const int theResultIndex); /// Creates a construction cresults diff --git a/src/Model/Model_ResultConstruction.cpp b/src/Model/Model_ResultConstruction.cpp index a5e1ccc9b..8d230ab37 100644 --- a/src/Model/Model_ResultConstruction.cpp +++ b/src/Model/Model_ResultConstruction.cpp @@ -14,13 +14,12 @@ boost::shared_ptr& Model_ResultConstruction::shape() return myShape; } +/* boost::shared_ptr Model_ResultConstruction::owner() { return myOwner; -} +}*/ -Model_ResultConstruction::Model_ResultConstruction( - const boost::shared_ptr& theFeature) - : myOwner(theFeature) +Model_ResultConstruction::Model_ResultConstruction() { } diff --git a/src/Model/Model_ResultConstruction.h b/src/Model/Model_ResultConstruction.h index b6ca72156..b24c2f310 100644 --- a/src/Model/Model_ResultConstruction.h +++ b/src/Model/Model_ResultConstruction.h @@ -28,7 +28,7 @@ public: /// Returns the shape-result produced by this feature MODEL_EXPORT virtual boost::shared_ptr& shape(); /// Returns the source feature of this result - MODEL_EXPORT virtual boost::shared_ptr owner(); + //MODEL_EXPORT virtual boost::shared_ptr owner(); protected: /// Makes a body on the given feature diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 4fd5f2965..0700c826b 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -34,10 +34,10 @@ void Model_Update::processEvent(const Events_Message* theMessage) // iterate all features of features-documents to update them set >::iterator aDIter = aDocs.begin(); for(; aDIter != aDocs.end(); aDIter++) { - int aNbFeatures = (*aDIter)->size(FEATURES_GROUP); + int aNbFeatures = (*aDIter)->size(ModelAPI_Feature::group()); for(int aFIndex = 0; aFIndex < aNbFeatures; aFIndex++) { boost::shared_ptr aFeature = - boost::dynamic_pointer_cast((*aDIter)->object(FEATURES_GROUP, aFIndex)); + boost::dynamic_pointer_cast((*aDIter)->object(ModelAPI_Feature::group(), aFIndex)); if (aFeature) updateFeature(aFeature); } diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 36342b3dd..740a4545e 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -15,18 +15,6 @@ class ModelAPI_Object; class ModelAPI_Result; class ModelAPI_ResultConstruction; -/// Common groups identifiers -/// Group of parameters -static const std::string PARAMETERS_GROUP = "Parameters"; -/// Group of constructions -static const std::string CONSTRUCTIONS_GROUP = "Construction"; -/// Group of parts -static const std::string PARTS_GROUP = "Parts"; -/// Group of bodies -static const std::string BODIES_GROUP = "Bodies"; -/// All created fetaures of the document (a history) -static const std::string FEATURES_GROUP = "Features"; - /**\class Model_Document * \ingroup DataModel * \brief Document for internal data structure of any object storage. diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index 0bdb7817e..daa59c05c 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -29,6 +29,10 @@ public: /// Returns the unique kind of a feature (like "Point") virtual const std::string& getKind() = 0; + /// Returns the group identifier of all features + static std::string group() + {static std::string MY_GROUP = "Features"; return MY_GROUP;} + /// Request for initialization of data model of the feature: adding all attributes virtual void initAttributes() = 0; @@ -37,6 +41,9 @@ public: // returns the current results of the feature std::list >& results() {return myResults;} + // returns the first result in the list or NULL reference + boost::shared_ptr firstResult() + {return myResults.size() ? *(myResults.begin()) : boost::shared_ptr();} /// Returns true if this feature must not be created: this is just an action /// that is not stored in the features history and data model (like "delete part"). diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index f801ad45c..336e6ccd4 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -21,7 +21,7 @@ class ModelAPI_ResultBody : public ModelAPI_Result public: /// Returns the group identifier of this result virtual std::string group() - {static std::string MY_GROUP = "Bodies"; return MY_GROUP;} + {static std::string MY_GROUP = "Bodies"; return MY_GROUP;} /// Stores the shape (called by the execution method). virtual void store(const boost::shared_ptr& theShape) = 0; diff --git a/src/SketchPlugin/SketchPlugin_Arc.h b/src/SketchPlugin/SketchPlugin_Arc.h index 5a4c6ed78..4603dd922 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.h +++ b/src/SketchPlugin/SketchPlugin_Arc.h @@ -37,13 +37,9 @@ public: SKETCHPLUGIN_EXPORT virtual void initAttributes(); /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( - boost::shared_ptr thePrevious); - - /// Adds sub-feature of the higher level feature (sub-element of the sketch) - /// \param theFeature sub-feature - SKETCHPLUGIN_EXPORT virtual const void addSub( - const FeaturePtr& theFeature) {}; + virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious) + {return simpleAISObject(firstResult(), thePrevious);} /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index d962d4cfa..1fec7a86a 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -26,7 +26,7 @@ void SketchPlugin_Circle::initAttributes() data()->addAttribute(CIRCLE_ATTR_RADIUS, ModelAPI_AttributeDouble::type()); } -void SketchPlugin_Circle::execute(boost::shared_ptr& theResult) +void SketchPlugin_Circle::execute() { SketchPlugin_Sketch* aSketch = sketch(); if (aSketch) { @@ -59,7 +59,9 @@ void SketchPlugin_Circle::execute(boost::shared_ptr& theResult) } boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes); // store the result - boost::dynamic_pointer_cast(theResult)->setShape(aCompound); + boost::shared_ptr aConstr = document()->createConstruction(); + aConstr->setShape(aCompound); + results().push_back(aConstr); } } diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index 2f2f01e42..c02c79e21 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -29,17 +29,15 @@ public: {static std::string MY_KIND = SKETCH_CIRCLE_KIND; return MY_KIND;} /// Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr& theResult); + SKETCHPLUGIN_EXPORT virtual void execute(); /// Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); - /// Returns the sketch preview - SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); - /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( - boost::shared_ptr thePrevious); + virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious) + {return simpleAISObject(firstResult(), thePrevious);} /// Adds sub-feature of the higher level feature (sub-element of the sketch) /// \param theFeature sub-feature diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp index 0fd8b0bff..e052d1ace 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp @@ -18,7 +18,7 @@ void SketchPlugin_ConstraintCoincidence::initAttributes() data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type()); } -void SketchPlugin_ConstraintCoincidence::execute(boost::shared_ptr& theResult) +void SketchPlugin_ConstraintCoincidence::execute() { } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h index f227d4cf8..3af35adfe 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h @@ -28,7 +28,7 @@ public: {static std::string MY_KIND = SKETCH_CONSTRAINT_COINCIDENCE_KIND; return MY_KIND;} /// \brief Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr& theResult); + SKETCHPLUGIN_EXPORT virtual void execute(); /// \brief Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 23ecc6435..faa2d7b62 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -30,7 +30,7 @@ void SketchPlugin_ConstraintDistance::initAttributes() data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type()); } -void SketchPlugin_ConstraintDistance::execute(boost::shared_ptr& theResult) +void SketchPlugin_ConstraintDistance::execute() { boost::shared_ptr aData = data(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index e633e9fe4..bb324f75b 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -29,7 +29,7 @@ public: {static std::string MY_KIND = SKETCH_CONSTRAINT_DISTANCE_KIND; return MY_KIND;} /// \brief Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr& theResult); + SKETCHPLUGIN_EXPORT virtual void execute(); /// \brief Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index 0a5a11fcc..71a35c4f1 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -26,7 +26,7 @@ void SketchPlugin_ConstraintLength::initAttributes() data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); } -void SketchPlugin_ConstraintLength::execute(boost::shared_ptr& theResult) +void SketchPlugin_ConstraintLength::execute() { if (data()->attribute(CONSTRAINT_ATTR_ENTITY_A)->isInitialized() && !data()->attribute(CONSTRAINT_ATTR_VALUE)->isInitialized()) { diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.h b/src/SketchPlugin/SketchPlugin_ConstraintLength.h index 3ad18ea20..8e8cd5a47 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.h @@ -29,7 +29,7 @@ public: {static std::string MY_KIND = SKETCH_CONSTRAINT_LENGTH_KIND; return MY_KIND;} /// \brief Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr& theResult); + SKETCHPLUGIN_EXPORT virtual void execute(); /// \brief Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp index 45713e124..85d34d9c7 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -25,7 +26,7 @@ void SketchPlugin_ConstraintParallel::initAttributes() data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type()); } -void SketchPlugin_ConstraintParallel::execute(boost::shared_ptr& theResult) +void SketchPlugin_ConstraintParallel::execute() { } @@ -51,8 +52,13 @@ boost::shared_ptr SketchPlugin_ConstraintParallel::getAISObje return thePrevious; boost::shared_ptr aPlane = sketch()->plane(); - boost::shared_ptr aLine1 = aLine1Feature->preview(); - boost::shared_ptr aLine2 = aLine2Feature->preview(); + boost::shared_ptr aLine1, aLine2; + boost::shared_ptr aConst1 = + boost::dynamic_pointer_cast(aLine1Feature->firstResult()); + if (aConst1) aLine1 = aConst1->shape(); + boost::shared_ptr aConst2 = + boost::dynamic_pointer_cast(aLine1Feature->firstResult()); + if (aConst2) aLine2 = aConst2->shape(); boost::shared_ptr aFlyoutAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h index 9fd42ba88..651016248 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h @@ -27,14 +27,11 @@ public: {static std::string MY_KIND = SKETCH_CONSTRAINT_PARALLEL_KIND; return MY_KIND;} /// \brief Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr& theResult); + SKETCHPLUGIN_EXPORT virtual void execute(); /// \brief Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); - /// \brief Returns the sketch preview - SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); - /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( boost::shared_ptr thePrevious); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp index b6b9de72a..ddd830858 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -25,7 +26,7 @@ void SketchPlugin_ConstraintPerpendicular::initAttributes() data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type()); } -void SketchPlugin_ConstraintPerpendicular::execute(boost::shared_ptr& theResult) +void SketchPlugin_ConstraintPerpendicular::execute() { } @@ -51,8 +52,13 @@ boost::shared_ptr SketchPlugin_ConstraintPerpendicular::getAI return thePrevious; boost::shared_ptr aPlane = sketch()->plane(); - boost::shared_ptr aLine1 = aLine1Feature->preview(); - boost::shared_ptr aLine2 = aLine2Feature->preview(); + boost::shared_ptr aLine1, aLine2; + boost::shared_ptr aConst1 = + boost::dynamic_pointer_cast(aLine1Feature->firstResult()); + if (aConst1) aLine1 = aConst1->shape(); + boost::shared_ptr aConst2 = + boost::dynamic_pointer_cast(aLine1Feature->firstResult()); + if (aConst2) aLine2 = aConst2->shape(); boost::shared_ptr anAIS = thePrevious; if (!anAIS) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h index 9f6956d91..231be4699 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h @@ -27,14 +27,11 @@ public: {static std::string MY_KIND = SKETCH_CONSTRAINT_PERPENDICULAR_KIND; return MY_KIND;} /// \brief Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr& theResult); + SKETCHPLUGIN_EXPORT virtual void execute(); /// \brief Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); - /// \brief Returns the sketch preview - SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); - /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( boost::shared_ptr thePrevious); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index ee05e7c9c..65ab125b5 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -30,7 +30,7 @@ void SketchPlugin_ConstraintRadius::initAttributes() data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type()); } -void SketchPlugin_ConstraintRadius::execute(boost::shared_ptr& theResult) +void SketchPlugin_ConstraintRadius::execute() { if (data()->attribute(CONSTRAINT_ATTR_ENTITY_A)->isInitialized() && !data()->attribute(CONSTRAINT_ATTR_VALUE)->isInitialized()) { diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h index c11757dfb..26642a49f 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h @@ -28,7 +28,7 @@ public: {static std::string MY_KIND = SKETCH_CONSTRAINT_RADIUS_KIND; return MY_KIND;} /// \brief Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr& theResult); + SKETCHPLUGIN_EXPORT virtual void execute(); /// \brief Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); diff --git a/src/SketchPlugin/SketchPlugin_Feature.cpp b/src/SketchPlugin/SketchPlugin_Feature.cpp index 7195bb706..99d5684d3 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.cpp +++ b/src/SketchPlugin/SketchPlugin_Feature.cpp @@ -4,6 +4,7 @@ #include #include #include +#include SketchPlugin_Feature::SketchPlugin_Feature() { @@ -34,11 +35,15 @@ SketchPlugin_Sketch* SketchPlugin_Feature::sketch() return mySketch; } -boost::shared_ptr SketchPlugin_Feature::prepareAISShape( - boost::shared_ptr thePrevious) +boost::shared_ptr SketchPlugin_Feature::simpleAISObject( + boost::shared_ptr theRes, boost::shared_ptr thePrevious) { - document()->result(); - boost::shared_ptr aPreview = preview(); + boost::shared_ptr aConstr = + boost::dynamic_pointer_cast(theRes); + + boost::shared_ptr aPreview; + if (aConstr) aPreview = aConstr->shape(); + boost::shared_ptr aResult = thePrevious; if (!aResult) aResult = boost::shared_ptr(new GeomAPI_AISObject()); diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 3d9cbf9a0..6f1b3a66c 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -23,17 +23,18 @@ class Handle_AIS_InteractiveObject; class SketchPlugin_Feature: public ModelAPI_Feature { public: - /// Returns the type of the feature result: it is allways construction element - virtual const std::string& getResultType() {return CONSTRUCTIONS_GROUP;} - /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( boost::shared_ptr thePrevious) = 0; + /// Simple creation of interactive object by the result of the object + static boost::shared_ptr simpleAISObject( + boost::shared_ptr theRes, boost::shared_ptr thePrevious); + /// Adds sub-feature of the higher level feature (sub-element of the sketch) /// \param theFeature sub-feature SKETCHPLUGIN_EXPORT virtual const void addSub( - const FeaturePtr& theFeature) = 0; + const FeaturePtr& theFeature) {}; /// Returns true if this feature must be displayed in the history (top level of Part tree) SKETCHPLUGIN_EXPORT virtual bool isInHistory() {return false;} diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index c15a8b62f..f61f24c0e 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -30,7 +30,7 @@ void SketchPlugin_Line::initAttributes() data()->addAttribute(LINE_ATTR_END, GeomDataAPI_Point2D::type()); } -void SketchPlugin_Line::execute(boost::shared_ptr& theResult) +void SketchPlugin_Line::execute() { SketchPlugin_Sketch* aSketch = sketch(); if (aSketch) { @@ -46,7 +46,9 @@ void SketchPlugin_Line::execute(boost::shared_ptr& theResult) // make linear edge boost::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); // store the result - boost::dynamic_pointer_cast(theResult)->setShape(anEdge); + boost::shared_ptr aConstr = document()->createConstruction(); + aConstr->setShape(anEdge); + results().push_back(aConstr); } } } diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index af454d8c9..cce6a25eb 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -30,19 +30,15 @@ public: {static std::string MY_KIND = SKETCH_LINE_KIND; return MY_KIND;} /// Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr& theResult); + SKETCHPLUGIN_EXPORT virtual void execute(); /// Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( - boost::shared_ptr thePrevious); - - /// Adds sub-feature of the higher level feature (sub-element of the sketch) - /// \param theFeature sub-feature - SKETCHPLUGIN_EXPORT virtual const void addSub( - const FeaturePtr& theFeature) {}; + boost::shared_ptr thePrevious) + {return simpleAISObject(firstResult(), thePrevious);} /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index 3a24b7a87..c910c6522 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -24,7 +24,7 @@ void SketchPlugin_Point::initAttributes() data()->addAttribute(POINT_ATTR_COORD, GeomDataAPI_Point2D::type()); } -void SketchPlugin_Point::execute(boost::shared_ptr& theResult) +void SketchPlugin_Point::execute() { SketchPlugin_Sketch* aSketch = sketch(); if (aSketch) { @@ -34,7 +34,9 @@ void SketchPlugin_Point::execute(boost::shared_ptr& theResult) boost::shared_ptr aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y())); // make a visible point boost::shared_ptr aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D); - boost::dynamic_pointer_cast(theResult)->setShape(aPointShape); + boost::shared_ptr aConstr = document()->createConstruction(); + aConstr->setShape(aPointShape); + results().push_back(aConstr); } } diff --git a/src/SketchPlugin/SketchPlugin_Point.h b/src/SketchPlugin/SketchPlugin_Point.h index ea3e125b7..4efb76d7c 100644 --- a/src/SketchPlugin/SketchPlugin_Point.h +++ b/src/SketchPlugin/SketchPlugin_Point.h @@ -28,19 +28,15 @@ public: {static std::string MY_KIND = SKETCH_POINT_KIND; return MY_KIND;} /// Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr& theResult); + SKETCHPLUGIN_EXPORT virtual void execute(); /// Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( - boost::shared_ptr thePrevious); - - /// Adds sub-feature of the higher level feature (sub-element of the sketch) - /// \param theFeature sub-feature - SKETCHPLUGIN_EXPORT virtual const void addSub( - const FeaturePtr& theFeature) {}; + virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious) + {return simpleAISObject(firstResult(), thePrevious);} /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index b451c99b0..813271dfa 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -36,7 +36,7 @@ void SketchPlugin_Sketch::initAttributes() data()->addAttribute(SKETCH_ATTR_FEATURES, ModelAPI_AttributeRefList::type()); } -void SketchPlugin_Sketch::execute(boost::shared_ptr& theResult) +void SketchPlugin_Sketch::execute() { if (!isPlaneSet()) { std::list > aFaces; @@ -45,7 +45,9 @@ void SketchPlugin_Sketch::execute(boost::shared_ptr& theResult) addPlane(0, 1, 0, aFaces); // XZ plane addPlane(0, 0, 1, aFaces); // XY plane boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces); - boost::dynamic_pointer_cast(theResult)->setShape(aCompound); + boost::shared_ptr aConstr = document()->createConstruction(); + aConstr->setShape(aCompound); + results().push_back(aConstr); return; } if (!data()->isValid()) @@ -74,7 +76,7 @@ void SketchPlugin_Sketch::execute(boost::shared_ptr& theResult) for (; anIt != aLast; anIt++) { aFeature = boost::dynamic_pointer_cast(*anIt); boost::shared_ptr aRes = - boost::dynamic_pointer_cast(document()->result(aFeature)); + boost::dynamic_pointer_cast(aFeature->firstResult()); if (aRes) { boost::shared_ptr aShape = aRes->shape(); if (aShape) @@ -91,17 +93,19 @@ void SketchPlugin_Sketch::execute(boost::shared_ptr& theResult) aLoops.insert(aLoops.end(), aWires.begin(), aWires.end()); boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aLoops); - boost::dynamic_pointer_cast(theResult)->setShape(aCompound); + boost::shared_ptr aConstr = document()->createConstruction(); + aConstr->setShape(aCompound); + results().push_back(aConstr); } boost::shared_ptr SketchPlugin_Sketch::getAISObject( boost::shared_ptr thePrevious) { - boost::shared_ptr anAIS = prepareAISShape(thePrevious); - anAIS->setColor(SKETCH_PLANE_COLOR); - anAIS->setWidth(SKETCH_WIDTH); + boost::shared_ptr aResult = simpleAISObject(firstResult(), thePrevious); + aResult->setColor(SKETCH_PLANE_COLOR); + aResult->setWidth(SKETCH_WIDTH); //anAIS->Redisplay(); - return anAIS; + return aResult; } const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature) diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 798019b18..c1dd3ecc1 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -36,12 +36,8 @@ public: SKETCHPLUGIN_EXPORT virtual const std::string& getKind() {static std::string MY_KIND = SKETCH_KIND; return MY_KIND;} - /// Returns to which group in the document must be added feature - SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() - {static std::string MY_GROUP = "Construction"; return MY_GROUP;} - /// Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr& theResult); + SKETCHPLUGIN_EXPORT virtual void execute(); /// Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); -- 2.39.2