From: mpv Date: Fri, 11 Jul 2014 13:37:49 +0000 (+0400) Subject: Making compilable all non-GUI classes X-Git-Tag: V_0.4.4~198 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=82f94d044ced40be786427ddee839e3c263fe277;p=modules%2Fshaper.git Making compilable all non-GUI classes --- diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index aaa697dd5..66dfdfdf1 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -7,6 +7,7 @@ #include "ModelAPI_Document.h" #include "ModelAPI_Data.h" #include "ModelAPI_AttributeDouble.h" +#include #include #include @@ -28,5 +29,7 @@ void ConstructionPlugin_Point::execute() boost::shared_ptr aPnt(new GeomAPI_Pnt( data()->real(POINT_ATTR_X)->value(), data()->real(POINT_ATTR_Y)->value(), data()->real(POINT_ATTR_Z)->value())); - data()->store(GeomAlgoAPI_PointBuilder::point(aPnt)); + boost::shared_ptr aConstr = document()->createConstruction(); + aConstr->setShape(GeomAlgoAPI_PointBuilder::point(aPnt)); + results().push_back(aConstr); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 328dde5f0..e89d50352 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include @@ -34,12 +36,19 @@ void FeaturesPlugin_Extrusion::execute() FeaturePtr aFaceFeature = aFaceRef->value(); if (!aFaceFeature) return; - boost::shared_ptr aFace = aFaceFeature->data()->shape(); + boost::shared_ptr aConstr = + boost::dynamic_pointer_cast(aFaceFeature->firstResult()); + if (!aConstr) + return; + boost::shared_ptr aFace = aConstr->shape(); if (!aFace) return; double aSize = data()->real(EXTRUSION_SIZE)->value(); if (data()->boolean(EXTRUSION_REVERSE)->value()) aSize = -aSize; - data()->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize)); + boost::shared_ptr aResult = document()->createBody(); + aResult->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize)); + document()->storeResult(data(), aResult); + setResult(aResult); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h index 95c8f98ae..01cb4fe3a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h @@ -28,10 +28,6 @@ public: FEATURESPLUGIN_EXPORT virtual const std::string& getKind() { static std::string MY_KIND = FEATURES_EXTRUSION_KIND; return MY_KIND; } - /// Returns to which group in the document must be added feature - FEATURESPLUGIN_EXPORT virtual const std::string& getGroup() - { static std::string MY_GROUP = "Construction"; return MY_GROUP; } - /// Creates a new part document if needed FEATURESPLUGIN_EXPORT virtual void execute(); diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index d94957494..241ac68c4 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -372,10 +372,10 @@ FeaturePtr Model_Document::addFeature(string theID) return aFeature; } -void Model_Document::storeResult(boost::shared_ptr theFeature, +void Model_Document::storeResult(boost::shared_ptr theFeatureData, boost::shared_ptr theResult, const int theResultIndex) { - initData(theResult, boost::dynamic_pointer_cast(theFeature->data())-> + initData(theResult, boost::dynamic_pointer_cast(theFeatureData)-> label().Father().FindChild(TAG_FEATURE_RESULTS), theResultIndex); } @@ -589,7 +589,7 @@ void Model_Document::initData(ObjectPtr theObj, TDF_Label& theLab, const int the boost::shared_ptr aThis = Model_Application::getApplication()->getDocument(myID); boost::shared_ptr aData(new Model_Data); - aData->setLabel(theLab.FindChild(theTag)); + aData->setLabel(theLab.FindChild(theTag + 1)); aData->setObject(theObj); theObj->setDoc(aThis); theObj->setData(aData); @@ -675,3 +675,15 @@ boost::shared_ptr Model_Document::createConstructio boost::shared_ptr aResult(new Model_ResultConstruction()); return aResult; } + +boost::shared_ptr Model_Document::createBody() +{ + boost::shared_ptr aResult(new Model_ResultBody()); + return aResult; +} + +boost::shared_ptr Model_Document::createPart() +{ + boost::shared_ptr aResult(new Model_ResultPart()); + return aResult; +} diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index ec69667b7..f0bc73845 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -88,11 +88,15 @@ 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(boost::shared_ptr theFeature, - boost::shared_ptr theResult, const int theResultIndex); + MODEL_EXPORT virtual void storeResult(boost::shared_ptr theFeatureData, + boost::shared_ptr theResult, const int theResultIndex = 0); /// Creates a construction cresults MODEL_EXPORT virtual boost::shared_ptr createConstruction(); + /// Creates a body results + MODEL_EXPORT virtual boost::shared_ptr createBody(); + /// Creates a part results + MODEL_EXPORT virtual boost::shared_ptr createPart(); protected: diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 687bc112c..fda4b4d8b 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -9,8 +9,7 @@ #include #include -Model_ResultBody::Model_ResultBody(const boost::shared_ptr& theFeature) - : myOwner(theFeature) +Model_ResultBody::Model_ResultBody() { } diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index 3757e5d1f..13402b2b6 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -29,7 +29,7 @@ public: protected: /// Makes a body on the given feature - Model_ResultBody(const boost::shared_ptr& theFeature); + Model_ResultBody(); friend class Model_Document; }; diff --git a/src/Model/Model_ResultConstruction.h b/src/Model/Model_ResultConstruction.h index b24c2f310..e312f6fda 100644 --- a/src/Model/Model_ResultConstruction.h +++ b/src/Model/Model_ResultConstruction.h @@ -20,9 +20,6 @@ class Model_ResultConstruction : public ModelAPI_ResultConstruction boost::shared_ptr myOwner; ///< owner of this result boost::shared_ptr myShape; ///< shape of this result created "on the fly" public: - /// Returns the group identifier of this result - virtual std::string group() - {static std::string MY_GROUP = "Construction"; return MY_GROUP;} /// Sets the result MODEL_EXPORT virtual void setShape(boost::shared_ptr theShape); /// Returns the shape-result produced by this feature diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index 38b72fad9..b3602c0b5 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -16,7 +16,6 @@ boost::shared_ptr Model_ResultPart::owner() return boost::shared_ptr(); // return empty pointer } -Model_ResultPart::Model_ResultPart( -const boost::shared_ptr& theFeature) +Model_ResultPart::Model_ResultPart() { } diff --git a/src/Model/Model_ResultPart.h b/src/Model/Model_ResultPart.h index b2daa5dfe..26c19fc0c 100644 --- a/src/Model/Model_ResultPart.h +++ b/src/Model/Model_ResultPart.h @@ -18,9 +18,6 @@ class Model_ResultPart : public ModelAPI_ResultPart { public: - /// Returns the group identifier of this result - virtual std::string group() - {static std::string MY_GROUP = "Parts"; return MY_GROUP;} /// Returns the part-document of this result MODEL_EXPORT virtual boost::shared_ptr partDoc(); /// Part has no stored feature: this method returns NULL @@ -28,7 +25,7 @@ public: protected: /// makes a result on a temporary feature (an action) - Model_ResultPart(const boost::shared_ptr& theFeature); + Model_ResultPart(); friend class Model_Document; }; diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index 8fd391b26..44e9dd81e 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -4,9 +4,9 @@ #include "ModelAPI.h" #include "ModelAPI_Document.h" #include "ModelAPI_PluginManager.h" + #include "ModelAPI_Object.h" #include "ModelAPI_Feature.h" #include "ModelAPI_Data.h" - #include "ModelAPI_Object.h" #include "ModelAPI_Attribute.h" #include "ModelAPI_AttributeDocRef.h" #include "ModelAPI_AttributeDouble.h" @@ -27,9 +27,9 @@ %include %shared_ptr(ModelAPI_Document) %shared_ptr(ModelAPI_PluginManager) +%shared_ptr(ModelAPI_Object) %shared_ptr(ModelAPI_Feature) %shared_ptr(ModelAPI_Data) -%shared_ptr(ModelAPI_Object) %shared_ptr(ModelAPI_Attribute) %shared_ptr(ModelAPI_AttributeDocRef) %shared_ptr(ModelAPI_AttributeDouble) @@ -39,9 +39,9 @@ // all supported interfaces %include "ModelAPI_Document.h" %include "ModelAPI_PluginManager.h" +%include "ModelAPI_Object.h" %include "ModelAPI_Feature.h" %include "ModelAPI_Data.h" -%include "ModelAPI_Object.h" %include "ModelAPI_Attribute.h" %include "ModelAPI_AttributeDocRef.h" %include "ModelAPI_AttributeDouble.h" diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 740a4545e..5e7c921ba 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -14,6 +14,9 @@ class ModelAPI_Feature; class ModelAPI_Object; class ModelAPI_Result; class ModelAPI_ResultConstruction; +class ModelAPI_ResultBody; +class ModelAPI_ResultPart; +class ModelAPI_Data; /**\class Model_Document * \ingroup DataModel @@ -86,6 +89,15 @@ public: /// Creates a construction cresults virtual boost::shared_ptr createConstruction() = 0; + /// Creates a body results + virtual boost::shared_ptr createBody() = 0; + /// Creates a part results + virtual boost::shared_ptr createPart() = 0; + + //! Allows to store the result in the data tree of the document (attaches 'data' of result to tree) + virtual void storeResult(boost::shared_ptr theFeatureData, + boost::shared_ptr theResult, const int theResultIndex = 0) = 0; + protected: /// Only for SWIG wrapping it is here diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index daa59c05c..1fd594525 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -39,11 +39,14 @@ public: /// Computes or recomputes the results virtual void execute() = 0; - // returns the current results of the feature + /// returns the current results of the feature std::list >& results() {return myResults;} - // returns the first result in the list or NULL reference + /// returns the first result in the list or NULL reference boost::shared_ptr firstResult() {return myResults.size() ? *(myResults.begin()) : boost::shared_ptr();} + /// sets the alone result + void setResult(const boost::shared_ptr& theResult) + {myResults.clear(); myResults.push_back(theResult);} /// 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_ResultConstruction.h b/src/ModelAPI/ModelAPI_ResultConstruction.h index ede2f73a4..3c12f482c 100644 --- a/src/ModelAPI/ModelAPI_ResultConstruction.h +++ b/src/ModelAPI/ModelAPI_ResultConstruction.h @@ -18,6 +18,10 @@ class ModelAPI_ResultConstruction : public ModelAPI_Result { public: + /// Returns the group identifier of this result + virtual std::string group() + {static std::string MY_GROUP = "Construction"; return MY_GROUP;} + /// Returns the shape-result produced by this feature virtual boost::shared_ptr& shape() = 0; diff --git a/src/ModelAPI/ModelAPI_ResultPart.h b/src/ModelAPI/ModelAPI_ResultPart.h index 575328b6a..60328906c 100644 --- a/src/ModelAPI/ModelAPI_ResultPart.h +++ b/src/ModelAPI/ModelAPI_ResultPart.h @@ -17,6 +17,10 @@ class ModelAPI_ResultPart : public ModelAPI_Result { public: + /// Returns the group identifier of this result + virtual std::string group() + {static std::string MY_GROUP = "Parts"; return MY_GROUP;} + /// Returns the part-document of this result virtual boost::shared_ptr partDoc() = 0; }; diff --git a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp index 9b6a47e16..68f34b00b 100644 --- a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp @@ -26,14 +26,14 @@ void PartSetPlugin_Duplicate::initAttributes() boost::shared_ptr aSource; // searching for source document attribute for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) { aSource = boost::dynamic_pointer_cast( - aRoot->feature(getGroup(), a, true)); + aRoot->object(ModelAPI_Feature::group(), a)); if (aSource->data()->docRef(PART_ATTR_DOC_REF)->value() == aPManager->currentDocument()) break; aSource.reset(); } if (aSource) { boost::shared_ptr aCopy = - aPManager->copy(aSource->data()->docRef(PART_ATTR_DOC_REF)->value(), data()->getName()); + aPManager->copy(aSource->data()->docRef(PART_ATTR_DOC_REF)->value(), data()->name()); aRef->setFeature(aSource); } } diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cpp b/src/PartSetPlugin/PartSetPlugin_Part.cpp index 628435a95..ebd970ca5 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Part.cpp @@ -7,6 +7,7 @@ #include "ModelAPI_Document.h" #include "ModelAPI_Data.h" #include "ModelAPI_AttributeDocRef.h" +#include using namespace std; @@ -25,7 +26,14 @@ void PartSetPlugin_Part::execute() if (!aDocRef->value()) { // create a document if not yet created boost::shared_ptr aPartSetDoc = ModelAPI_PluginManager::get()->rootDocument(); - aDocRef->setValue(aPartSetDoc->subDocument(data()->getName())); + aDocRef->setValue(aPartSetDoc->subDocument(data()->name())); + } + // create a result only once + if (results().empty()) { + boost::shared_ptr aResult = document()->createPart(); + document()->storeResult(data(), aResult); + if (aResult->data()->name().empty()) + aResult->data()->setName(data()->name()); } } diff --git a/src/PartSetPlugin/PartSetPlugin_Remove.cpp b/src/PartSetPlugin/PartSetPlugin_Remove.cpp index 0e09f3a60..d6f2bb23b 100644 --- a/src/PartSetPlugin/PartSetPlugin_Remove.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Remove.cpp @@ -15,7 +15,8 @@ void PartSetPlugin_Remove::execute() boost::shared_ptr aCurrent; boost::shared_ptr a; for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) { - FeaturePtr aFeature = aRoot->feature(getGroup(), a, true); + FeaturePtr aFeature = + boost::dynamic_pointer_cast(aRoot->object(ModelAPI_Feature::group(), a)); if (aFeature->getKind() == PARTSET_PART_KIND) { boost::shared_ptr aPart = boost::static_pointer_cast(aFeature); diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index 1fec7a86a..a99677bf8 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -61,7 +61,7 @@ void SketchPlugin_Circle::execute() // store the result boost::shared_ptr aConstr = document()->createConstruction(); aConstr->setShape(aCompound); - results().push_back(aConstr); + setResult(aConstr); } } diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index f61f24c0e..aaad3a61f 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -48,7 +48,7 @@ void SketchPlugin_Line::execute() // store the result boost::shared_ptr aConstr = document()->createConstruction(); aConstr->setShape(anEdge); - results().push_back(aConstr); + setResult(aConstr); } } } diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index c910c6522..87a3ac08f 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -36,7 +36,7 @@ void SketchPlugin_Point::execute() boost::shared_ptr aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D); boost::shared_ptr aConstr = document()->createConstruction(); aConstr->setShape(aPointShape); - results().push_back(aConstr); + setResult(aConstr); } } diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 813271dfa..0189bf561 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -47,7 +47,7 @@ void SketchPlugin_Sketch::execute() boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces); boost::shared_ptr aConstr = document()->createConstruction(); aConstr->setShape(aCompound); - results().push_back(aConstr); + setResult(aConstr); return; } if (!data()->isValid()) @@ -95,7 +95,7 @@ void SketchPlugin_Sketch::execute() boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aLoops); boost::shared_ptr aConstr = document()->createConstruction(); aConstr->setShape(aCompound); - results().push_back(aConstr); + setResult(aConstr); } boost::shared_ptr SketchPlugin_Sketch::getAISObject( diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index 985688043..41de682cb 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -65,34 +65,35 @@ void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessa { const ModelAPI_ObjectUpdatedMessage* anUpdateMsg = dynamic_cast(theMessage); - std::set< FeaturePtr > aFeatures = anUpdateMsg->features(); + std::set< ObjectPtr > aFeatures = anUpdateMsg->features(); bool isModifiedEvt = theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED); if (!isModifiedEvt) { - std::set< FeaturePtr >::iterator aFeatIter; + std::set< ObjectPtr >::iterator aFeatIter; for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { + FeaturePtr aFeature = boost::dynamic_pointer_cast(*aFeatIter); // Only sketches and constraints can be added by Create event - const std::string& aFeatureKind = (*aFeatIter)->getKind(); + const std::string& aFeatureKind = aFeature->getKind(); if (aFeatureKind.compare(SKETCH_KIND) == 0) { boost::shared_ptr aSketch = - boost::dynamic_pointer_cast(*aFeatIter); + boost::dynamic_pointer_cast(aFeature); if (aSketch) changeWorkplane(aSketch); continue; } boost::shared_ptr aConstraint = - boost::dynamic_pointer_cast(*aFeatIter); + boost::dynamic_pointer_cast(aFeature); if (aConstraint) changeConstraint(aConstraint); else { // Sketch plugin features can be only updated boost::shared_ptr aFeature = - boost::dynamic_pointer_cast(*aFeatIter); + boost::dynamic_pointer_cast(aFeature); if (aFeature) updateEntity(aFeature); } @@ -104,8 +105,8 @@ void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessa } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { - const ModelAPI_FeatureDeletedMessage* aDeleteMsg = - dynamic_cast(theMessage); + const ModelAPI_ObjectDeletedMessage* aDeleteMsg = + dynamic_cast(theMessage); const std::set& aFeatureGroups = aDeleteMsg->groups(); // Find SKETCH_KIND in groups. The constraint groups should be updated when an object removed from Sketch