From 5d9f5c6e19b94b5b2c4bf8d314b7f7f1c6f49897 Mon Sep 17 00:00:00 2001 From: sbh Date: Tue, 15 Jul 2014 16:11:05 +0400 Subject: [PATCH] Refactoring: static constants are replaced by inline functions in: Affected headers: * ModelAPI_Document.h * SketchPlugin_Arc.h * SketchPlugin_Line.h * SketchPlugin_Circle.h * SketchPlugin_Constraint.h * SketchPlugin_ConstraintDistance.h * SketchPlugin_ConstraintParallel.h * SketchPlugin_ConstraintLength.h * SketchPlugin_ConstraintRadius.h * SketchPlugin_ConstraintPerpendicular.h * SketchPlugin_ConstraintCoincidence.h * PartSetPlugin_Part.h * PartSetPlugin_Duplicate.h * SketchPlugin_Sketch.h * SketchPlugin_Point.h --- .../FeaturesPlugin_Extrusion.cpp | 12 ++-- src/FeaturesPlugin/FeaturesPlugin_Extrusion.h | 40 +++++++---- src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp | 2 +- src/Model/Model_Document.cpp | 12 ++-- src/Model/Model_Object.h | 2 +- src/Model/Model_Update.cpp | 4 +- src/ModelAPI/ModelAPI_Document.h | 36 +++++++--- src/PartSet/PartSet_Listener.cpp | 2 +- src/PartSet/PartSet_Module.cpp | 2 +- .../PartSet_OperationFeatureCreate.cpp | 20 +++--- src/PartSet/PartSet_OperationFeatureEdit.cpp | 4 +- src/PartSet/PartSet_OperationSketch.cpp | 12 ++-- src/PartSet/PartSet_OperationSketch.h | 2 +- src/PartSet/PartSet_TestOCC.cpp | 14 ++-- src/PartSet/PartSet_Tools.cpp | 38 +++++----- src/PartSetPlugin/PartSetPlugin_Duplicate.cpp | 8 +-- src/PartSetPlugin/PartSetPlugin_Duplicate.h | 9 ++- src/PartSetPlugin/PartSetPlugin_Part.cpp | 4 +- src/PartSetPlugin/PartSetPlugin_Part.h | 20 ++++-- src/PartSetPlugin/PartSetPlugin_Plugin.cpp | 2 +- src/PartSetPlugin/PartSetPlugin_Remove.cpp | 6 +- src/PartSetPlugin/PartSetPlugin_Remove.h | 11 +-- src/SketchPlugin/SketchPlugin_Arc.cpp | 26 +++---- src/SketchPlugin/SketchPlugin_Arc.h | 40 +++++++---- src/SketchPlugin/SketchPlugin_Circle.cpp | 14 ++-- src/SketchPlugin/SketchPlugin_Circle.h | 33 ++++++--- src/SketchPlugin/SketchPlugin_Constraint.h | 71 ++++++++++++++----- .../SketchPlugin_ConstraintCoincidence.cpp | 4 +- .../SketchPlugin_ConstraintCoincidence.h | 15 ++-- .../SketchPlugin_ConstraintDistance.cpp | 28 ++++---- .../SketchPlugin_ConstraintDistance.h | 16 +++-- .../SketchPlugin_ConstraintLength.cpp | 32 ++++----- .../SketchPlugin_ConstraintLength.h | 17 +++-- .../SketchPlugin_ConstraintParallel.cpp | 14 ++-- .../SketchPlugin_ConstraintParallel.h | 15 ++-- .../SketchPlugin_ConstraintPerpendicular.cpp | 12 ++-- .../SketchPlugin_ConstraintPerpendicular.h | 15 ++-- .../SketchPlugin_ConstraintRadius.cpp | 60 ++++++++-------- .../SketchPlugin_ConstraintRadius.h | 14 ++-- src/SketchPlugin/SketchPlugin_Feature.cpp | 2 +- src/SketchPlugin/SketchPlugin_Line.cpp | 16 ++--- src/SketchPlugin/SketchPlugin_Line.h | 31 +++++--- src/SketchPlugin/SketchPlugin_Plugin.cpp | 22 +++--- src/SketchPlugin/SketchPlugin_Point.cpp | 8 +-- src/SketchPlugin/SketchPlugin_Point.h | 22 +++--- src/SketchPlugin/SketchPlugin_Sketch.cpp | 34 ++++----- src/SketchPlugin/SketchPlugin_Sketch.h | 53 ++++++++++---- src/SketchSolver/SketchSolver_Constraint.cpp | 54 +++++++------- .../SketchSolver_ConstraintGroup.cpp | 63 +++++++++------- .../SketchSolver_ConstraintManager.cpp | 32 ++++----- src/XGUI/XGUI_ContextMenuMgr.cpp | 2 +- src/XGUI/XGUI_DocumentDataModel.cpp | 18 ++--- src/XGUI/XGUI_PartDataModel.cpp | 64 ++++++++--------- src/XGUI/XGUI_Workshop.cpp | 9 +-- 54 files changed, 647 insertions(+), 471 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 328dde5f0..0e8fc0b13 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -20,15 +20,15 @@ FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion() void FeaturesPlugin_Extrusion::initAttributes() { - data()->addAttribute(EXTRUSION_FACE, ModelAPI_AttributeReference::type()); - data()->addAttribute(EXTRUSION_SIZE, ModelAPI_AttributeDouble::type()); - data()->addAttribute(EXTRUSION_REVERSE, ModelAPI_AttributeBoolean::type()); + data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeReference::type()); + data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type()); + data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type()); } void FeaturesPlugin_Extrusion::execute() { boost::shared_ptr aFaceRef = - boost::dynamic_pointer_cast(data()->attribute(EXTRUSION_FACE)); + boost::dynamic_pointer_cast(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID())); if (!aFaceRef) return; FeaturePtr aFaceFeature = aFaceRef->value(); @@ -38,8 +38,8 @@ void FeaturesPlugin_Extrusion::execute() if (!aFace) return; - double aSize = data()->real(EXTRUSION_SIZE)->value(); - if (data()->boolean(EXTRUSION_REVERSE)->value()) + double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value(); + if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value()) aSize = -aSize; data()->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize)); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h index 95c8f98ae..cac857f15 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h @@ -8,25 +8,37 @@ #include "FeaturesPlugin.h" #include -/// Extrusion kind -const std::string FEATURES_EXTRUSION_KIND("Extrusion"); - -/// attribute name of referenced face -const std::string EXTRUSION_FACE = "extrusion_face"; - -/// attribute name of extrusion size -const std::string EXTRUSION_SIZE = "extrusion_size"; - -/// attribute name of reverse direction -const std::string EXTRUSION_REVERSE = "extrusion_reverse"; - - class FeaturesPlugin_Extrusion: public ModelAPI_Feature { public: + /// Extrusion kind + inline static const std::string& ID() + { + static const std::string MY_EXTRUSION_ID("Extrusion"); + return MY_EXTRUSION_ID; + } + /// attribute name of referenced face + inline static const std::string& FACE_ID() + { + static const std::string MY_FACE_ID("FeaturesPlugin_Extrusion::FACE_ID()"); + return MY_FACE_ID; + } + /// attribute name of extrusion size + inline static const std::string& SIZE_ID() + { + static const std::string MY_SIZE_ID("FeaturesPlugin_Extrusion::SIZE_ID()"); + return MY_SIZE_ID; + } + /// attribute name of reverse direction + inline static const std::string& REVERSE_ID() + { + static const std::string MY_REVERSE_ID("FeaturesPlugin_Extrusion::REVERSE_ID()"); + return MY_REVERSE_ID; + } + /// Returns the kind of a feature FEATURESPLUGIN_EXPORT virtual const std::string& getKind() - { static std::string MY_KIND = FEATURES_EXTRUSION_KIND; return MY_KIND; } + { static std::string MY_KIND = FeaturesPlugin_Extrusion::ID(); return MY_KIND; } /// Returns to which group in the document must be added feature FEATURESPLUGIN_EXPORT virtual const std::string& getGroup() diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index 1c9273d5f..1ae9381cd 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -17,7 +17,7 @@ FeaturesPlugin_Plugin::FeaturesPlugin_Plugin() FeaturePtr FeaturesPlugin_Plugin::createFeature(string theFeatureID) { - if (theFeatureID == FEATURES_EXTRUSION_KIND) { + if (theFeatureID == FeaturesPlugin_Extrusion::ID()) { return FeaturePtr(new FeaturesPlugin_Extrusion); } // feature of such kind is not found diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 95cc5a9d1..1c7015389 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -354,7 +354,7 @@ void Model_Document::addFeature(const FeaturePtr theFeature) boost::shared_ptr aThis = Model_Application::getApplication()->getDocument(myID); - TDF_Label aFeaturesLab = groupLabel(FEATURES_GROUP); + TDF_Label aFeaturesLab = groupLabel(ModelAPI_Document::FEATURES_GROUP()); TDF_Label aFeatureLab = aFeaturesLab.NewChild(); // organize feature and data objects @@ -440,7 +440,7 @@ 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_Document::FEATURES_GROUP()), aData->label()); // event: feature is added ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), theFeature->getGroup()); @@ -477,7 +477,7 @@ FeaturePtr Model_Document::feature( TDF_Label aFeatureLab = aRefs->Value(theIndex); FeaturePtr aFeature = feature(aFeatureLab); - if (theGroupID == FEATURES_GROUP || isOperation) { // just returns the feature from the history + if (theGroupID == ModelAPI_Document::FEATURES_GROUP() || isOperation) { // just returns the feature from the history return aFeature; } else { // create a new object from the group to return it Handle(TDataStd_Name) aName; // name of the object @@ -537,7 +537,7 @@ void Model_Document::setUniqueName(FeaturePtr theFeature) string aName; // result // iterate all features but also iterate group of this feature if object is not in history list aGroups; - aGroups.push_back(FEATURES_GROUP); + aGroups.push_back(ModelAPI_Document::FEATURES_GROUP()); if (!theFeature->isInHistory()) { aGroups.push_back(theFeature->getGroup()); } @@ -588,7 +588,7 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated) // update features vector::iterator aFIter = myFeatures.begin(); // and in parallel iterate labels of features - TDF_ChildIDIterator aFLabIter(groupLabel(FEATURES_GROUP), TDataStd_Comment::GetID()); + TDF_ChildIDIterator aFLabIter(groupLabel(ModelAPI_Document::FEATURES_GROUP()), TDataStd_Comment::GetID()); while(aFIter != myFeatures.end() || aFLabIter.More()) { static const int INFINITE_TAG = INT_MAX; // no label means that it exists somwhere in infinite int aFeatureTag = INFINITE_TAG; @@ -605,7 +605,7 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated) aFIter = myFeatures.erase(aFIter); // event: model is updated if (aFeature->isInHistory()) { - ModelAPI_EventCreator::get()->sendDeleted(aThis, FEATURES_GROUP); + ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_Document::FEATURES_GROUP()); } ModelAPI_EventCreator::get()->sendDeleted(aThis, aFeature->getGroup()); } else if (aDSTag < aFeatureTag) { // a new feature is inserted diff --git a/src/Model/Model_Object.h b/src/Model/Model_Object.h index 73975bc28..1de923837 100644 --- a/src/Model/Model_Object.h +++ b/src/Model/Model_Object.h @@ -35,7 +35,7 @@ public: MODEL_EXPORT virtual const std::string& getKind() {return myRef->getKind();} /// Returns to which group in the document must be added feature - MODEL_EXPORT virtual const std::string& getGroup() {return FEATURES_GROUP;} + MODEL_EXPORT virtual const std::string& getGroup() {return ModelAPI_Document::FEATURES_GROUP();} /// Returns document this feature belongs to MODEL_EXPORT virtual boost::shared_ptr document() diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 6c8bd6431..2db098aea 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -34,9 +34,9 @@ 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_Document::FEATURES_GROUP()); for(int aFIndex = 0; aFIndex < aNbFeatures; aFIndex++) { - boost::shared_ptr aFeature = (*aDIter)->feature(FEATURES_GROUP, aFIndex); + boost::shared_ptr aFeature = (*aDIter)->feature(ModelAPI_Document::FEATURES_GROUP(), aFIndex); if (aFeature) updateFeature(aFeature); } diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 9070718b4..42ee9c3ac 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -12,16 +12,6 @@ class ModelAPI_Feature; -/// 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"; -/// 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. @@ -31,6 +21,32 @@ static const std::string FEATURES_GROUP = "Features"; class ModelAPI_Document { public: + //! Common groups identifiers + //! Group of parameters + inline static const std::string& PARAMETERS_GROUP() + { + static const std::string MY_PARAMETERS_GROUP = "Parameters"; + return MY_PARAMETERS_GROUP; + } + //! Group of constructions + inline static const std::string& CONSTRUCTIONS_GROUP() + { + static const std::string MY_CONSTRUCTIONS_GROUP = "Construction"; + return MY_CONSTRUCTIONS_GROUP; + } + //! Group of parts + inline static const std::string& PARTS_GROUP() + { + static const std::string MY_PARTS_GROUP = "Parts"; + return MY_PARTS_GROUP; + } + //! All created fetaures of the document (a history) + inline static const std::string& FEATURES_GROUP() + { + static const std::string MY_FEATURES_GROUP = "Features"; + return MY_FEATURES_GROUP; + } + //! Loads the OCAF document from the file. //! \param theFileName full name of the file to load //! \param theStudyID identifier of the SALOME study to associate with loaded file diff --git a/src/PartSet/PartSet_Listener.cpp b/src/PartSet/PartSet_Listener.cpp index f9229d383..7b642812d 100644 --- a/src/PartSet/PartSet_Listener.cpp +++ b/src/PartSet/PartSet_Listener.cpp @@ -65,7 +65,7 @@ void PartSet_Listener::processEvent(const Events_Message* theMessage) std::set::const_iterator anIt = aGroups.begin(), aLast = aGroups.end(); for (; anIt != aLast; anIt++) { std::string aGroup = *anIt; - if (aGroup.compare(SKETCH_KIND) == 0) { // Update only Sketch group + if (aGroup.compare(SketchPlugin_Sketch::ID()) == 0) { // Update only Sketch group myModule->workshop()->displayer()->eraseDeletedFeatures(); myModule->updateCurrentPreview(aGroup); } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 2824363e1..5f903b0ed 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -510,7 +510,7 @@ void PartSet_Module::editFeature(FeaturePtr theFeature) if (!theFeature) return; -// if (theFeature->getKind() == SKETCH_KIND) { +// if (theFeature->getKind() == SketchPlugin_Sketch::ID()) { FeaturePtr aFeature = theFeature; if (XGUI_Tools::isModelObject(aFeature)) { ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index d1d5d409b..9b7039ae3 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -54,15 +54,15 @@ PartSet_OperationFeatureCreate::~PartSet_OperationFeatureCreate() bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId) { - return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND || - theId == SKETCH_CIRCLE_KIND || - theId == SKETCH_ARC_KIND || - theId == SKETCH_CONSTRAINT_DISTANCE_KIND || - theId == SKETCH_CONSTRAINT_LENGTH_KIND || - theId == SKETCH_CONSTRAINT_RADIUS_KIND || - theId == SKETCH_CONSTRAINT_PARALLEL_KIND || - theId == SKETCH_CONSTRAINT_PERPENDICULAR_KIND || - theId == SKETCH_CONSTRAINT_COINCIDENCE_KIND; + return theId == SketchPlugin_Line::ID() || theId == SketchPlugin_Point::ID() || + theId == SketchPlugin_Circle::ID() || + theId == SketchPlugin_Arc::ID() || + theId == SketchPlugin_ConstraintDistance::ID() || + theId == SketchPlugin_ConstraintLength::ID() || + theId == SketchPlugin_ConstraintRadius::ID() || + theId == SketchPlugin_ConstraintParallel::ID() || + theId == SketchPlugin_ConstraintPerpendicular::ID() || + theId == SketchPlugin_ConstraintCoincidence::ID(); } bool PartSet_OperationFeatureCreate::canBeCommitted() const @@ -138,7 +138,7 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle { PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); // move to selected line - if (feature()->getKind() == SKETCH_LINE_KIND) { + if (feature()->getKind() == SketchPlugin_Line::ID()) { //FeaturePtr aFeature = aPrs.feature(); //projectPointOnLine(aFeature, myPointSelectionMode, aPoint, theView, aX, anY); } diff --git a/src/PartSet/PartSet_OperationFeatureEdit.cpp b/src/PartSet/PartSet_OperationFeatureEdit.cpp index c6ad6130e..5782ca1ba 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.cpp +++ b/src/PartSet/PartSet_OperationFeatureEdit.cpp @@ -142,9 +142,9 @@ void PartSet_OperationFeatureEdit::mouseDoubleClick(QMouseEvent* theEvent, Handl Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aFeaturePrs.owner()); if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) { bool isValid; - double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid); + double aValue = PartSet_Tools::featureValue(feature(), SketchPlugin_Constraint::VALUE(), isValid); if (isValid) { - ModuleBase_WidgetEditor::editFeatureValue(feature(), CONSTRAINT_ATTR_VALUE); + ModuleBase_WidgetEditor::editFeatureValue(feature(), SketchPlugin_Constraint::VALUE()); flushUpdated(); } } diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 563caf21c..df4408dd5 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -143,7 +143,7 @@ std::list PartSet_OperationSketch::subFeatures() const if (!aData->isValid()) return std::list(); boost::shared_ptr aRefList = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_FEATURES)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::FEATURES_ID())); return aRefList->list(); } @@ -175,7 +175,7 @@ bool PartSet_OperationSketch::hasSketchPlane() const boost::shared_ptr aData = feature()->data(); AttributeDoublePtr anAttr; boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::NORM_ID())); aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0); } return aHasPlane; @@ -212,16 +212,16 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) boost::shared_ptr aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir))); boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); anOrigin->setValue(anOrigPnt); boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::NORM_ID())); aNormal->setValue(aNormDir); boost::shared_ptr aDirX = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::DIRX_ID())); aDirX->setValue(aXDir); boost::shared_ptr aDirY = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::DIRY_ID())); aDirY->setValue(aYDir); boost::shared_ptr aDir = aPlane->direction(); diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index eb0c84775..bf8694bb5 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -24,7 +24,7 @@ class PARTSET_EXPORT PartSet_OperationSketch : public PartSet_OperationSketchBas Q_OBJECT public: /// Returns the operation type key - static std::string Type() { return SKETCH_KIND; } + static std::string Type() { return SketchPlugin_Sketch::ID(); } public: /// Constructor diff --git a/src/PartSet/PartSet_TestOCC.cpp b/src/PartSet/PartSet_TestOCC.cpp index f447f5966..aaa3c3c59 100644 --- a/src/PartSet/PartSet_TestOCC.cpp +++ b/src/PartSet/PartSet_TestOCC.cpp @@ -132,7 +132,7 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) if (aPreviewOp) { // create a line boost::shared_ptr aDoc = ModelAPI_PluginManager::get()->rootDocument(); - FeaturePtr aFeature = aDoc->addFeature(SKETCH_LINE_KIND); + FeaturePtr aFeature = aDoc->addFeature(SketchPlugin_Line::ID()); if (aFeature) // TODO: generate an error if feature was not created aFeature->execute(); @@ -140,8 +140,8 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) boost::dynamic_pointer_cast(aPreviewOp->sketch()); aSketch->addSub(aFeature); - PartSet_Tools::setFeaturePoint(aFeature, 100, 100, LINE_ATTR_START); - PartSet_Tools::setFeaturePoint(aFeature, 150, 300, LINE_ATTR_END); + PartSet_Tools::setFeaturePoint(aFeature, 100, 100, SketchPlugin_Line::START_ID()); + PartSet_Tools::setFeaturePoint(aFeature, 150, 300, SketchPlugin_Line::END_ID()); boost::shared_ptr aPreview = PartSet_OperationSketchBase::preview(aFeature); @@ -163,8 +163,8 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) /*double aDelta = -200; for (int i = 0; i < 20; i++) { aDelta = aDelta - i*2; - PartSet_Tools::setFeaturePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START); - PartSet_Tools::setFeaturePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END); + PartSet_Tools::setFeaturePoint(aFeature, 100+aDelta, 200+aDelta, SketchPlugin_Line::START_ID()); + PartSet_Tools::setFeaturePoint(aFeature, 300+aDelta, 500+aDelta, SketchPlugin_Line::END_ID()); boost::shared_ptr aPreview = PartSet_OperationSketchBase::preview(aFeature); Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( @@ -199,8 +199,8 @@ void PartSet_TestOCC::changeTestLine(XGUI_Workshop* theWorkshop) myTestDelta = myTestDelta - 50; double aDelta = myTestDelta; - PartSet_Tools::setFeaturePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, LINE_ATTR_START); - PartSet_Tools::setFeaturePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END); + PartSet_Tools::setFeaturePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, SketchPlugin_Line::START_ID()); + PartSet_Tools::setFeaturePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, SketchPlugin_Line::END_ID()); boost::shared_ptr aPreview = PartSet_OperationSketchBase::preview(aFeature); boost::shared_ptr aPrevAIS; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index aa3ac235a..eb07e5baa 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -77,12 +77,12 @@ void PartSet_Tools::convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch, boost::shared_ptr aData = theSketch->data(); boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); boost::shared_ptr aX = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::DIRX_ID())); boost::shared_ptr anY = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::DIRY_ID())); gp_Pnt anOriginPnt(anOrigin->x(), anOrigin->y(), anOrigin->z()); gp_Vec aVec(anOriginPnt, thePoint); @@ -100,7 +100,7 @@ void PartSet_Tools::convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch, anEyeVec.Normalize(); boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::NORM_ID())); gp_Vec aNormalVec(aNormal->x(), aNormal->y(), aNormal->z()); double aDen = anEyeVec * aNormalVec; @@ -123,11 +123,11 @@ void PartSet_Tools::convertTo3D(const double theX, const double theY, boost::shared_ptr aData = theSketch->data(); boost::shared_ptr aC = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); boost::shared_ptr aX = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::DIRX_ID())); boost::shared_ptr aY = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::DIRY_ID())); boost::shared_ptr aSum = aC->pnt()->xyz()->added( aX->dir()->xyz()->multiplied(theX))->added(aY->dir()->xyz()->multiplied(theY)); @@ -238,7 +238,7 @@ void PartSet_Tools::createConstraint(FeaturePtr theSketch, boost::shared_ptr thePoint2) { boost::shared_ptr aDoc = document(); - FeaturePtr aFeature = aDoc->addFeature(SKETCH_CONSTRAINT_COINCIDENCE_KIND); + FeaturePtr aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID()); if (theSketch) { boost::shared_ptr aSketch = @@ -249,11 +249,11 @@ void PartSet_Tools::createConstraint(FeaturePtr theSketch, boost::shared_ptr aData = aFeature->data(); boost::shared_ptr aRef1 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); aRef1->setAttr(thePoint1); boost::shared_ptr aRef2 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::ENTITY_B())); aRef2->setAttr(thePoint2); if (aFeature) // TODO: generate an error if feature was not created @@ -275,7 +275,7 @@ void PartSet_Tools::setConstraints(FeaturePtr theSketch, FeaturePtr theFeature, // the constraint is created between the feature point and the found sketch point boost::shared_ptr aData = theSketch->data(); boost::shared_ptr aRefList = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_FEATURES)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::FEATURES_ID())); std::list aFeatures = aRefList->list(); std::list::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); @@ -308,9 +308,9 @@ boost::shared_ptr PartSet_Tools::sketchPlane(FeaturePtr theSketch) boost::shared_ptr aData = theSketch->data(); boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::NORM_ID())); aA = aNormal->x(); aB = aNormal->y(); aC = aNormal->z(); @@ -329,18 +329,18 @@ boost::shared_ptr PartSet_Tools::point3D( return aPoint; boost::shared_ptr aC = - boost::dynamic_pointer_cast(theSketch->data()->attribute(SKETCH_ATTR_ORIGIN)); + boost::dynamic_pointer_cast(theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); boost::shared_ptr aX = - boost::dynamic_pointer_cast(theSketch->data()->attribute(SKETCH_ATTR_DIRX)); + boost::dynamic_pointer_cast(theSketch->data()->attribute(SketchPlugin_Sketch::DIRX_ID())); boost::shared_ptr aY = - boost::dynamic_pointer_cast(theSketch->data()->attribute(SKETCH_ATTR_DIRY)); + boost::dynamic_pointer_cast(theSketch->data()->attribute(SketchPlugin_Sketch::DIRY_ID())); return thePoint2D->to3D(aC->pnt(), aX->dir(), aY->dir()); } bool PartSet_Tools::isConstraintFeature(const std::string& theKind) { - return theKind == SKETCH_CONSTRAINT_DISTANCE_KIND || - theKind == SKETCH_CONSTRAINT_LENGTH_KIND || - theKind == SKETCH_CONSTRAINT_RADIUS_KIND; + return theKind == SketchPlugin_ConstraintDistance::ID() || + theKind == SketchPlugin_ConstraintLength::ID() || + theKind == SketchPlugin_ConstraintRadius::ID(); } diff --git a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp index 9b6a47e16..726f6487b 100644 --- a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp @@ -17,9 +17,9 @@ PartSetPlugin_Duplicate::PartSetPlugin_Duplicate() void PartSetPlugin_Duplicate::initAttributes() { PartSetPlugin_Part::initAttributes(); - data()->addAttribute(PART_DUPLICATE_ATTR_REF, ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(PartSetPlugin_Duplicate::DOC_REF(), ModelAPI_AttributeRefAttr::type()); - boost::shared_ptr aRef = data()->refattr(PART_DUPLICATE_ATTR_REF); + boost::shared_ptr aRef = data()->refattr(PartSetPlugin_Duplicate::DOC_REF()); if (!aRef->attr()) { // create a copy: if not created yet attribute is not initialized boost::shared_ptr aPManager = ModelAPI_PluginManager::get(); boost::shared_ptr aRoot = aPManager->rootDocument(); @@ -27,13 +27,13 @@ void PartSetPlugin_Duplicate::initAttributes() for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) { aSource = boost::dynamic_pointer_cast( aRoot->feature(getGroup(), a, true)); - if (aSource->data()->docRef(PART_ATTR_DOC_REF)->value() == aPManager->currentDocument()) + if (aSource->data()->docRef(PartSetPlugin_Part::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(PartSetPlugin_Part::DOC_REF())->value(), data()->getName()); aRef->setFeature(aSource); } } diff --git a/src/PartSetPlugin/PartSetPlugin_Duplicate.h b/src/PartSetPlugin/PartSetPlugin_Duplicate.h index 9bab4d63e..dc64d2aec 100644 --- a/src/PartSetPlugin/PartSetPlugin_Duplicate.h +++ b/src/PartSetPlugin/PartSetPlugin_Duplicate.h @@ -7,9 +7,6 @@ #include "PartSetPlugin_Part.h" -/// the reference to copy: reference to the attribute -const std::string PART_DUPLICATE_ATTR_REF = "Origin"; - /**\class PartSetPlugin_Duplicate * \ingroup DataModel * \brief Duplicates the active part (not root). Creates a new "part" feature. @@ -17,6 +14,12 @@ const std::string PART_DUPLICATE_ATTR_REF = "Origin"; class PartSetPlugin_Duplicate: public PartSetPlugin_Part { public: + /// the reference to copy: reference to the attribute + inline static const std::string& DOC_REF() + { + static const std::string MY_DUPLICATE_ID("Origin"); + return MY_DUPLICATE_ID; + } /// Makes a new part, copy of active PartSetPlugin_Duplicate(); diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cpp b/src/PartSetPlugin/PartSetPlugin_Part.cpp index 628435a95..4fff734b8 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Part.cpp @@ -16,12 +16,12 @@ PartSetPlugin_Part::PartSetPlugin_Part() void PartSetPlugin_Part::initAttributes() { - data()->addAttribute(PART_ATTR_DOC_REF, ModelAPI_AttributeDocRef::type()); + data()->addAttribute(PartSetPlugin_Part::DOC_REF(), ModelAPI_AttributeDocRef::type()); } void PartSetPlugin_Part::execute() { - boost::shared_ptr aDocRef = data()->docRef(PART_ATTR_DOC_REF); + boost::shared_ptr aDocRef = data()->docRef(PartSetPlugin_Part::DOC_REF()); if (!aDocRef->value()) { // create a document if not yet created boost::shared_ptr aPartSetDoc = ModelAPI_PluginManager::get()->rootDocument(); diff --git a/src/PartSetPlugin/PartSetPlugin_Part.h b/src/PartSetPlugin/PartSetPlugin_Part.h index 0f9217271..cd656b18e 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.h +++ b/src/PartSetPlugin/PartSetPlugin_Part.h @@ -8,12 +8,6 @@ #include "PartSetPlugin.h" #include -/// Part kind -const std::string PARTSET_PART_KIND("Part"); - -/// part reference attribute -const std::string PART_ATTR_DOC_REF = "PartDocument"; - /**\class PartSetPlugin_Part * \ingroup DataModel * \brief Feature for creation of the new part in PartSet. @@ -21,9 +15,21 @@ const std::string PART_ATTR_DOC_REF = "PartDocument"; class PartSetPlugin_Part: public ModelAPI_Feature { public: + /// Part kind + inline static const std::string& ID() + { + static const std::string MY_PART_KIND("Part"); + return MY_PART_KIND; + } + /// part reference attribute + inline static const std::string& DOC_REF() + { + static const std::string MY_DOC_REF("PartDocument"); + return MY_DOC_REF; + } /// Returns the kind of a feature PARTSETPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = PARTSET_PART_KIND; return MY_KIND;} + {static std::string MY_KIND = PartSetPlugin_Part::ID(); return MY_KIND;} /// Returns to which group in the document must be added feature PARTSETPLUGIN_EXPORT virtual const std::string& getGroup() diff --git a/src/PartSetPlugin/PartSetPlugin_Plugin.cpp b/src/PartSetPlugin/PartSetPlugin_Plugin.cpp index 4ba7fa5ca..dc384608e 100644 --- a/src/PartSetPlugin/PartSetPlugin_Plugin.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Plugin.cpp @@ -18,7 +18,7 @@ PartSetPlugin_Plugin::PartSetPlugin_Plugin() FeaturePtr PartSetPlugin_Plugin::createFeature(string theFeatureID) { - if (theFeatureID == PARTSET_PART_KIND) { + if (theFeatureID == PartSetPlugin_Part::ID()) { return FeaturePtr(new PartSetPlugin_Part); } if (theFeatureID == "duplicate") { diff --git a/src/PartSetPlugin/PartSetPlugin_Remove.cpp b/src/PartSetPlugin/PartSetPlugin_Remove.cpp index 0e09f3a60..2aea700f2 100644 --- a/src/PartSetPlugin/PartSetPlugin_Remove.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Remove.cpp @@ -16,12 +16,12 @@ void PartSetPlugin_Remove::execute() boost::shared_ptr a; for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) { FeaturePtr aFeature = aRoot->feature(getGroup(), a, true); - if (aFeature->getKind() == PARTSET_PART_KIND) { + if (aFeature->getKind() == PartSetPlugin_Part::ID()) { boost::shared_ptr aPart = boost::static_pointer_cast(aFeature); - if (aPart->data()->docRef(PART_ATTR_DOC_REF)->value() == aPManager->currentDocument()) { + if (aPart->data()->docRef(PartSetPlugin_Part::DOC_REF())->value() == aPManager->currentDocument()) { // do remove - aPart->data()->docRef(PART_ATTR_DOC_REF)->value()->close(); + aPart->data()->docRef(PartSetPlugin_Part::DOC_REF())->value()->close(); aRoot->removeFeature(aPart); } } diff --git a/src/PartSetPlugin/PartSetPlugin_Remove.h b/src/PartSetPlugin/PartSetPlugin_Remove.h index 87b7e258c..a24cc2632 100644 --- a/src/PartSetPlugin/PartSetPlugin_Remove.h +++ b/src/PartSetPlugin/PartSetPlugin_Remove.h @@ -8,9 +8,6 @@ #include "PartSetPlugin.h" #include -/// Extrusion kind -const std::string PARTSET_REMOVE_KIND("Remove"); - /**\class PartSetPlugin_Remove * \ingroup DataModel * \brief Feature for creation of the new part in PartSet. @@ -18,9 +15,15 @@ const std::string PARTSET_REMOVE_KIND("Remove"); class PartSetPlugin_Remove: public ModelAPI_Feature { public: + /// Remove kind + inline static const std::string& ID() + { + static const std::string MY_REMOVE_KIND("Remove"); + return MY_REMOVE_KIND; + } /// Returns the kind of a feature PARTSETPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = PARTSET_REMOVE_KIND; return MY_KIND;} + {static std::string MY_KIND = PartSetPlugin_Remove::ID(); return MY_KIND;} /// Returns to which group in the document must be added feature PARTSETPLUGIN_EXPORT virtual const std::string& getGroup() diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index e166608d1..89e2185de 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -25,9 +25,9 @@ SketchPlugin_Arc::SketchPlugin_Arc() void SketchPlugin_Arc::initAttributes() { - data()->addAttribute(ARC_ATTR_CENTER, GeomDataAPI_Point2D::type()); - data()->addAttribute(ARC_ATTR_START, GeomDataAPI_Point2D::type()); - data()->addAttribute(ARC_ATTR_END, GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Arc::CENTER_ID(), GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Arc::START_ID(), GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Arc::END_ID(), GeomDataAPI_Point2D::type()); } void SketchPlugin_Arc::execute() @@ -42,10 +42,10 @@ const boost::shared_ptr& SketchPlugin_Arc::preview() // compute a circle point in 3D view boost::shared_ptr aCenterAttr = - boost::dynamic_pointer_cast(data()->attribute(ARC_ATTR_CENTER)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Arc::CENTER_ID())); // compute the arc start point boost::shared_ptr aStartAttr = - boost::dynamic_pointer_cast(data()->attribute(ARC_ATTR_START)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Arc::START_ID())); if (aCenterAttr->isInitialized() && aStartAttr->isInitialized()) { boost::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); // make a visible point @@ -54,7 +54,7 @@ const boost::shared_ptr& SketchPlugin_Arc::preview() // make a visible circle boost::shared_ptr aNDir = - boost::dynamic_pointer_cast(aSketch->data()->attribute(SKETCH_ATTR_NORM)); + boost::dynamic_pointer_cast(aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0); if (aHasPlane) { boost::shared_ptr aNormal = aNDir->dir(); @@ -62,7 +62,7 @@ const boost::shared_ptr& SketchPlugin_Arc::preview() // compute and change the arc end point boost::shared_ptr anEndAttr = - boost::dynamic_pointer_cast(data()->attribute(ARC_ATTR_END)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Arc::END_ID())); if (anEndAttr->isInitialized()) { boost::shared_ptr aCircleForArc( @@ -98,15 +98,15 @@ void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_CENTER)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::CENTER_ID())); aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_START)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::START_ID())); aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY); boost::shared_ptr aPoint3 = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_END)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::END_ID())); aPoint3->setValue(aPoint3->x() + theDeltaX, aPoint3->y() + theDeltaY); } @@ -116,17 +116,17 @@ double SketchPlugin_Arc::distanceToPoint(const boost::shared_ptr& boost::shared_ptr aData = data(); boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_CENTER)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::CENTER_ID())); aDelta = aPoint1->pnt()->distance(thePoint); boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_START)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::START_ID())); double aDistance = aPoint2->pnt()->distance(thePoint); if (aDelta < aDistance) aDelta = aDistance; boost::shared_ptr aPoint3 = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_END)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::END_ID())); aDistance = aPoint3->pnt()->distance(thePoint); if (aDelta < aDistance) aDelta = aDistance; diff --git a/src/SketchPlugin/SketchPlugin_Arc.h b/src/SketchPlugin/SketchPlugin_Arc.h index 946607795..cf57516a5 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.h +++ b/src/SketchPlugin/SketchPlugin_Arc.h @@ -9,16 +9,6 @@ #include #include -/// Arc feature kind -const std::string SKETCH_ARC_KIND("SketchArc"); - -/// Central 2D point of the circle which contains the arc -const std::string ARC_ATTR_CENTER("ArcCenter"); -/// Start 2D point of the arc -const std::string ARC_ATTR_START("ArcStartPoint"); -/// End 2D point of the arc -const std::string ARC_ATTR_END("ArcEndPoint"); - /**\class SketchPlugin_Arc * \ingroup DataModel * \brief Feature for creation of the new arc of circle in PartSet. @@ -26,13 +16,39 @@ const std::string ARC_ATTR_END("ArcEndPoint"); class SketchPlugin_Arc: public SketchPlugin_Feature { public: + /// Arc feature kind + inline static const std::string& ID() + { + static const std::string MY_SKETCH_ARC_ID("SketchArc"); + return MY_SKETCH_ARC_ID; + } + + /// Central 2D point of the circle which contains the arc + inline static const std::string& CENTER_ID() + { + static const std::string MY_CENTER_ID = "ArcCenter"; + return MY_CENTER_ID; + } + /// Start 2D point of the arc + inline static const std::string& START_ID() + { + static const std::string MY_START_ID = "ArcStartPoint"; + return MY_START_ID; + } + /// End 2D point of the arc + inline static const std::string& END_ID() + { + static const std::string MY_END_ID = "ArcEndPoint"; + return MY_END_ID; + } + /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = SKETCH_ARC_KIND; return MY_KIND;} + {static std::string MY_KIND = SketchPlugin_Arc::ID(); 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 = SKETCH_KIND; return MY_GROUP;} + {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;} /// Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index 593716ed9..5438c216d 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -24,8 +24,8 @@ SketchPlugin_Circle::SketchPlugin_Circle() void SketchPlugin_Circle::initAttributes() { - data()->addAttribute(CIRCLE_ATTR_CENTER, GeomDataAPI_Point2D::type()); - data()->addAttribute(CIRCLE_ATTR_RADIUS, ModelAPI_AttributeDouble::type()); + data()->addAttribute(SketchPlugin_Circle::CENTER_ID(), GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Circle::RADIUS_ID(), ModelAPI_AttributeDouble::type()); } void SketchPlugin_Circle::execute() @@ -40,9 +40,9 @@ const boost::shared_ptr& SketchPlugin_Circle::preview() // compute a circle point in 3D view boost::shared_ptr aCenterAttr = - boost::dynamic_pointer_cast(data()->attribute(CIRCLE_ATTR_CENTER)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Circle::CENTER_ID())); AttributeDoublePtr aRadiusAttr = - boost::dynamic_pointer_cast(data()->attribute(CIRCLE_ATTR_RADIUS)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Circle::RADIUS_ID())); if (aCenterAttr->isInitialized() && aRadiusAttr->isInitialized()) { boost::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); // make a visible point @@ -51,7 +51,7 @@ const boost::shared_ptr& SketchPlugin_Circle::preview() // make a visible circle boost::shared_ptr aNDir = - boost::dynamic_pointer_cast(aSketch->data()->attribute(SKETCH_ATTR_NORM)); + boost::dynamic_pointer_cast(aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0); if (aHasPlane) { boost::shared_ptr aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z())); @@ -82,7 +82,7 @@ void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Circle::CENTER_ID())); aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); } @@ -90,7 +90,7 @@ double SketchPlugin_Circle::distanceToPoint(const boost::shared_ptr aData = data(); boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Circle::CENTER_ID())); return aPoint->pnt()->distance(thePoint); } diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index bb47c214d..cf7de0330 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -9,14 +9,6 @@ #include #include -/// Circle feature kind -const std::string SKETCH_CIRCLE_KIND("SketchCircle"); - -/// 2D point - center of the circle -const std::string CIRCLE_ATTR_CENTER("CircleCenter"); -/// Radius of the circle -const std::string CIRCLE_ATTR_RADIUS("CircleRadius"); - /**\class SketchPlugin_Circle * \ingroup DataModel * \brief Feature for creation of the new circle in PartSet. @@ -24,13 +16,34 @@ const std::string CIRCLE_ATTR_RADIUS("CircleRadius"); class SketchPlugin_Circle: public SketchPlugin_Feature { public: + /// Circle feature kind + inline static const std::string& ID() + { + static const std::string MY_CIRCLE_ID("SketchCircle"); + return MY_CIRCLE_ID; + } + + /// 2D point - center of the circle + inline static const std::string& CENTER_ID() + { + static const std::string MY_CIRCLE_CENTER_ID("CircleCenter"); + return MY_CIRCLE_CENTER_ID; + } + + /// Radius of the circle + inline static const std::string& RADIUS_ID() + { + static const std::string MY_CIRCLE_RADIUS_ID("CircleRadius"); + return MY_CIRCLE_RADIUS_ID; + } + /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = SKETCH_CIRCLE_KIND; return MY_KIND;} + {static std::string MY_KIND = SketchPlugin_Circle::ID(); 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 = SKETCH_KIND; return MY_GROUP;} + {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;} /// Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_Constraint.h b/src/SketchPlugin/SketchPlugin_Constraint.h index 5db923562..b46214fb8 100644 --- a/src/SketchPlugin/SketchPlugin_Constraint.h +++ b/src/SketchPlugin/SketchPlugin_Constraint.h @@ -25,24 +25,9 @@ * * Also the list of possible attributes is provided to simplify assignment. */ -/// The value parameter for the constraint -const std::string CONSTRAINT_ATTR_VALUE("ConstraintValue"); -/// The 2D value parameter for the constraint -const std::string CONSTRAINT_ATTR_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt"); -/// First entity for the constraint -const std::string CONSTRAINT_ATTR_ENTITY_A("ConstraintEntityA"); -/// Second entity for the constraint -const std::string CONSTRAINT_ATTR_ENTITY_B("ConstraintEntityB"); -/// Third entity for the constraint -const std::string CONSTRAINT_ATTR_ENTITY_C("ConstraintEntityC"); -/// Fourth entity for the constraint -const std::string CONSTRAINT_ATTR_ENTITY_D("ConstraintEntityD"); -/// List of constraint attributes -const unsigned int CONSTRAINT_ATTR_SIZE = 4; -const std::string CONSTRAINT_ATTRIBUTES[CONSTRAINT_ATTR_SIZE] = - {CONSTRAINT_ATTR_ENTITY_A, CONSTRAINT_ATTR_ENTITY_B, - CONSTRAINT_ATTR_ENTITY_C, CONSTRAINT_ATTR_ENTITY_D}; +/// Size of the list of constraint attributes +const unsigned int CONSTRAINT_ATTR_SIZE = 4; /** \class SketchPlugin_Constraint * \ingroup DataModel @@ -52,9 +37,59 @@ const std::string CONSTRAINT_ATTRIBUTES[CONSTRAINT_ATTR_SIZE] = class SketchPlugin_Constraint: public SketchPlugin_Feature { public: + /// The value parameter for the constraint + inline static const std::string& VALUE() + { + static const std::string MY_CONSTRAINT_VALUE("ConstraintValue"); + return MY_CONSTRAINT_VALUE; + } + /// The 2D value parameter for the constraint + inline static const std::string& FLYOUT_VALUE_PNT() + { + static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt"); + return MY_FLYOUT_VALUE_PNT; + } + /// First entity for the constraint + inline static const std::string& ENTITY_A() + { + static const std::string MY_ENTITY_A("ConstraintEntityA"); + return MY_ENTITY_A; + } + /// Second entity for the constraint + inline static const std::string& ENTITY_B() + { + static const std::string MY_ENTITY_B("ConstraintEntityB"); + return MY_ENTITY_B; + } + /// Third entity for the constraint + inline static const std::string& ENTITY_C() + { + static const std::string MY_ENTITY_C("ConstraintEntityC"); + return MY_ENTITY_C; + } + /// Fourth entity for the constraint + inline static const std::string& ENTITY_D() + { + static const std::string MY_ENTITY_D("ConstraintEntityD"); + return MY_ENTITY_D; + } + + /// List of constraint attributes + inline static const std::string& ATTRIBUTE(const int theNumber) { + switch (theNumber) { + case 0: return ENTITY_A(); + case 1: return ENTITY_B(); + case 2: return ENTITY_C(); + case 3: return ENTITY_D(); + default: break; + } + static const std::string EMPTY_STRING(""); + return EMPTY_STRING; + } + /// \brief Returns to which group in the document must be added feature SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() - {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} + {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;} /** \brief 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 e052d1ace..fe6392825 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp @@ -14,8 +14,8 @@ SketchPlugin_ConstraintCoincidence::SketchPlugin_ConstraintCoincidence() void SketchPlugin_ConstraintCoincidence::initAttributes() { - data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); - data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type()); } void SketchPlugin_ConstraintCoincidence::execute() diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h index 9ed0e9653..3a5c2c31d 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h @@ -10,26 +10,29 @@ #include #include -/// Coincidence constraint kind -const std::string SKETCH_CONSTRAINT_COINCIDENCE_KIND("SketchConstraintCoincidence"); - /** \class SketchPlugin_ConstraintCoincidence * \ingroup DataModel * \brief Feature for creation of a new constraint which defines equivalence of two points * * These constraint has two attributes: - * CONSTRAINT_ATTR_ENTITY_A and CONSTRAINT_ATTR_ENTITY_B + * SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() */ class SketchPlugin_ConstraintCoincidence: public SketchPlugin_Constraint { public: + /// Parallel constraint kind + inline static const std::string& ID() + { + static const std::string MY_CONSTRAINT_COINCIDENCE_ID("SketchConstraintCoincidence"); + return MY_CONSTRAINT_COINCIDENCE_ID; + } /// \brief Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = SKETCH_CONSTRAINT_COINCIDENCE_KIND; return MY_KIND;} + {static std::string MY_KIND = SketchPlugin_ConstraintCoincidence::ID(); return MY_KIND;} /// \brief Returns to which group in the document must be added feature SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() - {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} + {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;} /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index faa2d7b62..2896843c5 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -24,21 +24,21 @@ SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance() void SketchPlugin_ConstraintDistance::initAttributes() { - data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type()); - data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type()); - data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); - data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::type()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type()); } void SketchPlugin_ConstraintDistance::execute() { boost::shared_ptr aData = data(); - boost::shared_ptr aPoint_A = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_A); - boost::shared_ptr aPoint_B = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_B); + boost::shared_ptr aPoint_A = getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A()); + boost::shared_ptr aPoint_B = getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B()); if (aPoint_A && aPoint_B) { AttributeDoublePtr anAttr_Value = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::VALUE())); if (!anAttr_Value->isInitialized()) { anAttr_Value->setValue(aPoint_A->pnt()->distance(aPoint_B->pnt())); @@ -55,13 +55,13 @@ boost::shared_ptr SketchPlugin_ConstraintDistance::getAISObje boost::shared_ptr aPlane = sketch()->plane(); DataPtr aData = data(); - boost::shared_ptr aPoint_A = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_A); - boost::shared_ptr aPoint_B = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_B); + boost::shared_ptr aPoint_A = getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A()); + boost::shared_ptr aPoint_B = getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B()); if (!aPoint_A || !aPoint_B) return thePrevious; boost::shared_ptr aFlyOutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); boost::shared_ptr aPoint1 = sketch()->to3D(aPoint_A->x(), aPoint_A->y()); boost::shared_ptr aPoint2 = sketch()->to3D(aPoint_B->x(), aPoint_B->y()); @@ -71,7 +71,7 @@ boost::shared_ptr SketchPlugin_ConstraintDistance::getAISObje // value calculation boost::shared_ptr aValueAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::VALUE())); double aValue = aValueAttr->value(); boost::shared_ptr anAIS = thePrevious; @@ -88,7 +88,7 @@ void SketchPlugin_ConstraintDistance::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); } @@ -106,9 +106,9 @@ boost::shared_ptr getFeaturePoint(DataPtr theData, if (anAttr) aFeature = anAttr->feature(); - if (aFeature && aFeature->getKind() == SKETCH_POINT_KIND) + if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) aPointAttr = boost::dynamic_pointer_cast - (aFeature->data()->attribute(POINT_ATTR_COORD)); + (aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); else { if (anAttr->attr()) aPointAttr = boost::dynamic_pointer_cast(anAttr->attr()); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index 4350e3cb4..9a538ab4a 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -10,27 +10,31 @@ #include #include -/// Distance constraint kind -const std::string SKETCH_CONSTRAINT_DISTANCE_KIND("SketchConstraintDistance"); - /** \class SketchPlugin_ConstraintDistance * \ingroup DataModel * \brief Feature for creation of a new constraint which defines a distance * between a point and another feature (point, line, plane or face) * * These constraint has three attributes: - * CONSTRAINT_ATTR_VALUE, CONSTRAINT_ATTR_ENTITY_A and CONSTRAINT_ATTR_ENTITY_B + * SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() */ class SketchPlugin_ConstraintDistance: public SketchPlugin_Constraint { public: + /// Distance constraint kind + inline static const std::string& ID() + { + static const std::string MY_CONSTRAINT_DISTANCE_ID("SketchConstraintDistance"); + return MY_CONSTRAINT_DISTANCE_ID; + } + /// \brief Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = SKETCH_CONSTRAINT_DISTANCE_KIND; return MY_KIND;} + {static std::string MY_KIND = SketchPlugin_ConstraintDistance::ID(); return MY_KIND;} /// \brief Returns to which group in the document must be added feature SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() - {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} + {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;} /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index 71a35c4f1..1953add2b 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -21,30 +21,30 @@ SketchPlugin_ConstraintLength::SketchPlugin_ConstraintLength() void SketchPlugin_ConstraintLength::initAttributes() { - data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type()); - data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type()); - data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::type()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); } void SketchPlugin_ConstraintLength::execute() { - if (data()->attribute(CONSTRAINT_ATTR_ENTITY_A)->isInitialized() && - !data()->attribute(CONSTRAINT_ATTR_VALUE)->isInitialized()) { + if (data()->attribute(SketchPlugin_Constraint::ENTITY_A())->isInitialized() && + !data()->attribute(SketchPlugin_Constraint::VALUE())->isInitialized()) { boost::shared_ptr aRef = - boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); FeaturePtr aFeature = aRef->feature(); if (aFeature) { // set length value boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aFeature->data()->attribute(LINE_ATTR_START)); + boost::dynamic_pointer_cast(aFeature->data()->attribute(SketchPlugin_Line::START_ID())); boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aFeature->data()->attribute(LINE_ATTR_END)); + boost::dynamic_pointer_cast(aFeature->data()->attribute(SketchPlugin_Line::END_ID())); double aLenght = aPoint1->pnt()->distance(aPoint2->pnt()); boost::shared_ptr aValueAttr = - boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_VALUE)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Constraint::VALUE())); aValueAttr->setValue(aLenght); } } @@ -59,21 +59,21 @@ boost::shared_ptr SketchPlugin_ConstraintLength::getAISObject boost::shared_ptr aPlane = sketch()->plane(); boost::shared_ptr anAttr = - boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); if (!anAttr) return thePrevious; FeaturePtr aFeature = anAttr->feature(); - if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND) + if (!aFeature || aFeature->getKind() != SketchPlugin_Line::ID()) return thePrevious; boost::shared_ptr aFlyOutAttr = - boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); DataPtr aData = aFeature->data(); boost::shared_ptr aStartPoint = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::START_ID())); boost::shared_ptr anEndPoint = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::END_ID())); boost::shared_ptr aPoint1 = sketch()->to3D(aStartPoint->x(), aStartPoint->y()); boost::shared_ptr aPoint2 = sketch()->to3D(anEndPoint->x(), anEndPoint->y()); @@ -83,7 +83,7 @@ boost::shared_ptr SketchPlugin_ConstraintLength::getAISObject // value calculation boost::shared_ptr aValueAttr = - boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_VALUE)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Constraint::VALUE())); double aValue = aValueAttr->value(); boost::shared_ptr anAIS = thePrevious; @@ -100,7 +100,7 @@ void SketchPlugin_ConstraintLength::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.h b/src/SketchPlugin/SketchPlugin_ConstraintLength.h index 3d07ce186..237dc8e86 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.h @@ -10,27 +10,30 @@ #include #include -/// Length constraint kind -const std::string SKETCH_CONSTRAINT_LENGTH_KIND("SketchConstraintLength"); - /** \class SketchPlugin_ConstraintLength * \ingroup DataModel * \brief Feature for creation of a new constraint which defines a length of a line segment * * These constraint has two attributes: - * CONSTRAINT_ATTR_VALUE (length) and CONSTRAINT_ATTR_ENTITY_A (segment), - * CONSTRAINT_ATTR_FLYOUT_VALUE_PNT (distance of a constraints handle) + * SketchPlugin_Constraint::VALUE() (length) and SketchPlugin_Constraint::ENTITY_A() (segment), + * SketchPlugin_Constraint::FLYOUT_VALUE_PNT() (distance of a constraints handle) */ class SketchPlugin_ConstraintLength: public SketchPlugin_Constraint { public: + /// Length constraint kind + inline static const std::string& ID() + { + static const std::string MY_CONSTRAINT_LENGTH_ID("SketchConstraintLength"); + return MY_CONSTRAINT_LENGTH_ID; + } /// \brief Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = SKETCH_CONSTRAINT_LENGTH_KIND; return MY_KIND;} + {static std::string MY_KIND = SketchPlugin_ConstraintLength::ID(); return MY_KIND;} /// \brief Returns to which group in the document must be added feature SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() - {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} + {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;} /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp index e45980582..15cc861ad 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp @@ -20,9 +20,9 @@ SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel() void SketchPlugin_ConstraintParallel::initAttributes() { - data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); - data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type()); - data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); } void SketchPlugin_ConstraintParallel::execute() @@ -44,9 +44,9 @@ boost::shared_ptr SketchPlugin_ConstraintParallel::getAISObje boost::shared_ptr aData = data(); boost::shared_ptr anAttr1 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); boost::shared_ptr anAttr2 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::ENTITY_B())); if (!anAttr1 || !anAttr1->isFeature() || !anAttr2 || !anAttr2->isFeature()) return thePrevious; @@ -62,7 +62,7 @@ boost::shared_ptr SketchPlugin_ConstraintParallel::getAISObje boost::shared_ptr aLine2 = aLine2Feature->preview(); boost::shared_ptr aFlyoutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); boost::shared_ptr aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); boost::shared_ptr anAIS = thePrevious; @@ -79,7 +79,7 @@ void SketchPlugin_ConstraintParallel::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY); } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h index 7f92e2e56..52e68fcd0 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h @@ -9,26 +9,29 @@ #include #include "SketchPlugin_Constraint.h" -/// Parallel constraint kind -const std::string SKETCH_CONSTRAINT_PARALLEL_KIND("SketchConstraintParallel"); - /** \class SketchPlugin_ConstraintParallel * \ingroup DataModel * \brief Feature for creation of a new constraint parallelism of two lines * * These constraint has two attributes: - * CONSTRAINT_ATTR_ENTITY_A and CONSTRAINT_ATTR_ENTITY_B + * SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() */ class SketchPlugin_ConstraintParallel: public SketchPlugin_Constraint { public: + /// Parallel constraint kind + inline static const std::string& ID() + { + static const std::string MY_CONSTRAINT_PARALLEL_ID("SketchConstraintParallel"); + return MY_CONSTRAINT_PARALLEL_ID; + } /// \brief Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = SKETCH_CONSTRAINT_PARALLEL_KIND; return MY_KIND;} + {static std::string MY_KIND = SketchPlugin_ConstraintParallel::ID(); return MY_KIND;} /// \brief Returns to which group in the document must be added feature SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() - {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} + {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;} /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp index d4d73b003..012220231 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp @@ -20,9 +20,9 @@ SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular() void SketchPlugin_ConstraintPerpendicular::initAttributes() { - data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); - data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type()); - data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); } void SketchPlugin_ConstraintPerpendicular::execute() @@ -43,9 +43,9 @@ boost::shared_ptr SketchPlugin_ConstraintPerpendicular::getAI boost::shared_ptr aData = data(); boost::shared_ptr anAttr1 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); boost::shared_ptr anAttr2 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::ENTITY_B())); if (!anAttr1 || !anAttr1->isFeature() || !anAttr2 || !anAttr2->isFeature()) return thePrevious; @@ -74,7 +74,7 @@ void SketchPlugin_ConstraintPerpendicular::move(double theDeltaX, double theDelt return; boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY); } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h index 2bb4a7b63..f6970a895 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h @@ -9,26 +9,29 @@ #include #include "SketchPlugin_Constraint.h" -/// Perpendicular constraint kind -const std::string SKETCH_CONSTRAINT_PERPENDICULAR_KIND("SketchConstraintPerpendicular"); - /** \class SketchPlugin_ConstraintPerpendicular * \ingroup DataModel * \brief Feature for creation of a new constraint for perpendicularity of two lines * * These constraint has two attributes: - * CONSTRAINT_ATTR_ENTITY_A and CONSTRAINT_ATTR_ENTITY_B + * SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() */ class SketchPlugin_ConstraintPerpendicular: public SketchPlugin_Constraint { public: + /// Perpendicular constraint kind + inline static const std::string& ID() + { + static const std::string MY_CONSTRAINT_PERPENDICULAR_ID("SketchConstraintPerpendicular"); + return MY_CONSTRAINT_PERPENDICULAR_ID; + } /// \brief Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = SKETCH_CONSTRAINT_PERPENDICULAR_KIND; return MY_KIND;} + {static std::string MY_KIND = SketchPlugin_ConstraintPerpendicular::ID(); return MY_KIND;} /// \brief Returns to which group in the document must be added feature SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() - {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} + {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;} /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index 65ab125b5..0b4cd5a9b 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -25,38 +25,38 @@ SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius() void SketchPlugin_ConstraintRadius::initAttributes() { - data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type()); - data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); - data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); } void SketchPlugin_ConstraintRadius::execute() { - if (data()->attribute(CONSTRAINT_ATTR_ENTITY_A)->isInitialized() && - !data()->attribute(CONSTRAINT_ATTR_VALUE)->isInitialized()) { + if (data()->attribute(SketchPlugin_Constraint::ENTITY_A())->isInitialized() && + !data()->attribute(SketchPlugin_Constraint::VALUE())->isInitialized()) { boost::shared_ptr aRef = - boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); FeaturePtr aFeature = aRef->feature(); if (aFeature) { double aRadius = 0; boost::shared_ptr aData = aFeature->data(); - if (aFeature->getKind() == SKETCH_CIRCLE_KIND) { + if (aFeature->getKind() == SketchPlugin_Circle::ID()) { AttributeDoublePtr anAttribute = boost::dynamic_pointer_cast - (aData->attribute(CIRCLE_ATTR_RADIUS)); + (aData->attribute(SketchPlugin_Circle::RADIUS_ID())); if (anAttribute) aRadius = anAttribute->value(); } - else if (aFeature->getKind() == SKETCH_ARC_KIND) { + else if (aFeature->getKind() == SketchPlugin_Arc::ID()) { boost::shared_ptr aCenterAttr = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_CENTER)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::CENTER_ID())); boost::shared_ptr aStartAttr = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_START)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::START_ID())); if (aCenterAttr && aStartAttr) aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); } boost::shared_ptr aValueAttr = - boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_VALUE)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Constraint::VALUE())); aValueAttr->setValue(aRadius); } } @@ -70,17 +70,17 @@ boost::shared_ptr SketchPlugin_ConstraintRadius::getAISObject boost::shared_ptr aData = data(); boost::shared_ptr anAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); if (!anAttr) return thePrevious; FeaturePtr aFeature = anAttr->feature(); std::string aKind = aFeature ? aFeature->getKind() : ""; - if (aKind != SKETCH_CIRCLE_KIND && aKind != SKETCH_ARC_KIND) + if (aKind != SketchPlugin_Circle::ID() && aKind != SketchPlugin_Arc::ID()) return thePrevious; // Flyout point boost::shared_ptr aFlyoutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); if (!aFlyoutAttr->isInitialized()) return thePrevious; boost::shared_ptr aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); @@ -89,28 +89,28 @@ boost::shared_ptr SketchPlugin_ConstraintRadius::getAISObject aData = aFeature->data(); boost::shared_ptr aCenterAttr; double aRadius; - if (aKind == SKETCH_CIRCLE_KIND) { - aCenterAttr = boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); + if (aKind == SketchPlugin_Circle::ID()) { + aCenterAttr = boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Circle::CENTER_ID())); AttributeDoublePtr aCircRadius = - boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_RADIUS)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Circle::RADIUS_ID())); aRadius = aCircRadius->value(); } - else if (aKind == SKETCH_ARC_KIND) { - aCenterAttr = boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_CENTER)); + else if (aKind == SketchPlugin_Arc::ID()) { + aCenterAttr = boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::CENTER_ID())); boost::shared_ptr aStartAttr = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_START)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Arc::START_ID())); aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); } boost::shared_ptr aCenter = sketch()->to3D(aCenterAttr->x(), aCenterAttr->y()); boost::shared_ptr aNDir = - boost::dynamic_pointer_cast(sketch()->data()->attribute(SKETCH_ATTR_NORM)); + boost::dynamic_pointer_cast(sketch()->data()->attribute(SketchPlugin_Sketch::NORM_ID())); boost::shared_ptr aNormal = aNDir->dir(); boost::shared_ptr aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius)); // Value boost::shared_ptr aValueAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::VALUE())); double aValue = aRadius; if (aValueAttr && aValueAttr->isInitialized()) aValue = aValueAttr->value(); @@ -129,15 +129,15 @@ void SketchPlugin_ConstraintRadius::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aRef = - boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); FeaturePtr aFeature = aRef->feature(); if (!aFeature) return; std::string aCenterAttrName; - if (aFeature->getKind() == SKETCH_CIRCLE_KIND) - aCenterAttrName = CIRCLE_ATTR_CENTER; - else if (aFeature->getKind() == SKETCH_ARC_KIND) - aCenterAttrName = ARC_ATTR_CENTER; + if (aFeature->getKind() == SketchPlugin_Circle::ID()) + aCenterAttrName = SketchPlugin_Circle::CENTER_ID(); + else if (aFeature->getKind() == SketchPlugin_Arc::ID()) + aCenterAttrName = SketchPlugin_Arc::CENTER_ID(); boost::shared_ptr aCenterAttr = boost::dynamic_pointer_cast(aFeature->data()->attribute(aCenterAttrName)); boost::shared_ptr aCenter = aCenterAttr->pnt(); @@ -145,11 +145,11 @@ void SketchPlugin_ConstraintRadius::move(double theDeltaX, double theDeltaY) // The specified delta applied on the circle curve, // so it will be scaled due to distance between flyout and center points boost::shared_ptr aFlyoutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); boost::shared_ptr aFlyout = aFlyoutAttr->pnt(); boost::shared_ptr aRadius = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::VALUE())); double aScale = aFlyout->distance(aCenter) / aRadius->value(); boost::shared_ptr aCircle(new GeomAPI_Circ2d(aCenter, aFlyout)); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h index a2e9abad8..a3a85d878 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h @@ -9,27 +9,29 @@ #include #include "SketchPlugin_Constraint.h" -/// Radius constraint kind -const std::string SKETCH_CONSTRAINT_RADIUS_KIND("SketchConstraintRadius"); - /** \class SketchPlugin_ConstraintRadius * \ingroup DataModel * \brief Feature for creation of a new constraint which defines * a radius of a circle or an arc of circle * * These constraint has two attributes: - * CONSTRAINT_ATTR_VALUE (radius), CONSTRAINT_ATTR_ENTITY_A (a circle) + * SketchPlugin_Constraint::VALUE() (radius), SketchPlugin_Constraint::ENTITY_A() (a circle) */ class SketchPlugin_ConstraintRadius: public SketchPlugin_Constraint { public: + /// Radius constraint kind + inline static const std::string& ID() { + static const std::string MY_CONSTRAINT_RADIUS_ID("SketchConstraintRadius"); + return MY_CONSTRAINT_RADIUS_ID; + } /// \brief Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = SKETCH_CONSTRAINT_RADIUS_KIND; return MY_KIND;} + {static std::string MY_KIND = SketchPlugin_ConstraintRadius::ID(); return MY_KIND;} /// \brief Returns to which group in the document must be added feature SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() - {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} + {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;} /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_Feature.cpp b/src/SketchPlugin/SketchPlugin_Feature.cpp index 4404ea1b8..d264007e3 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.cpp +++ b/src/SketchPlugin/SketchPlugin_Feature.cpp @@ -30,7 +30,7 @@ SketchPlugin_Sketch* SketchPlugin_Feature::sketch() dynamic_pointer_cast(document()->feature("Construction", a, true)); if (aSketch) { std::list aList = - aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list(); + aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list(); std::list::iterator aSub = aList.begin(); for(; aSub != aList.end(); aSub++) { if ((*aSub)->data()->isEqual(data())) { diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index 3175ac13f..db0e86c86 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -25,8 +25,8 @@ SketchPlugin_Line::SketchPlugin_Line() void SketchPlugin_Line::initAttributes() { - data()->addAttribute(LINE_ATTR_START, GeomDataAPI_Point2D::type()); - data()->addAttribute(LINE_ATTR_END, GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Line::START_ID(), GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Line::END_ID(), GeomDataAPI_Point2D::type()); } void SketchPlugin_Line::execute() @@ -39,10 +39,10 @@ const boost::shared_ptr& SketchPlugin_Line::preview() if (aSketch) { // compute a start point in 3D view boost::shared_ptr aStartAttr = - boost::dynamic_pointer_cast(data()->attribute(LINE_ATTR_START)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Line::START_ID())); // compute an end point in 3D view boost::shared_ptr anEndAttr = - boost::dynamic_pointer_cast(data()->attribute(LINE_ATTR_END)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Line::END_ID())); if (aStartAttr->isInitialized() && anEndAttr->isInitialized()) { boost::shared_ptr aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); boost::shared_ptr anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); @@ -68,11 +68,11 @@ void SketchPlugin_Line::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::START_ID())); aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::END_ID())); aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY); } @@ -82,9 +82,9 @@ double SketchPlugin_Line::distanceToPoint(const boost::shared_ptr boost::shared_ptr aData = data(); boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::START_ID())); boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::END_ID())); GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y()); diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index f440bac1d..2adb9a833 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -10,14 +10,6 @@ #include #include -/// Line feature kind -const std::string SKETCH_LINE_KIND("SketchLine"); - -/// Start 2D point of the line -const std::string LINE_ATTR_START("StartPoint"); -/// End 2D point of the line -const std::string LINE_ATTR_END("EndPoint"); - /**\class SketchPlugin_Line * \ingroup DataModel * \brief Feature for creation of the new part in PartSet. @@ -25,13 +17,32 @@ const std::string LINE_ATTR_END("EndPoint"); class SketchPlugin_Line: public SketchPlugin_Feature { public: + /// Arc feature kind + inline static const std::string& ID() + { + static const std::string SKETCH_LINE_ID("SketchLine"); + return SKETCH_LINE_ID; + } + /// Start 2D point of the line + inline static const std::string& START_ID() + { + static const std::string MY_START_ID("StartPoint"); + return MY_START_ID; + } + /// End 2D point of the line + inline static const std::string& END_ID() + { + static const std::string MY_END_ID("EndPoint"); + return MY_END_ID; + } + /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = SKETCH_LINE_KIND; return MY_KIND;} + {static std::string MY_KIND = SketchPlugin_Line::ID(); 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 = SKETCH_KIND; return MY_GROUP;} + {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;} /// Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index d494a6379..9c0da3f59 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -26,37 +26,37 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID) { - if (theFeatureID == SKETCH_KIND) { + if (theFeatureID == SketchPlugin_Sketch::ID()) { return FeaturePtr(new SketchPlugin_Sketch); } - else if (theFeatureID == SKETCH_POINT_KIND) { + else if (theFeatureID == SketchPlugin_Point::ID()) { return FeaturePtr(new SketchPlugin_Point); } - else if (theFeatureID == SKETCH_LINE_KIND) { + else if (theFeatureID == SketchPlugin_Line::ID()) { return FeaturePtr(new SketchPlugin_Line); } - else if (theFeatureID == SKETCH_CIRCLE_KIND) { + else if (theFeatureID == SketchPlugin_Circle::ID()) { return FeaturePtr(new SketchPlugin_Circle); } - else if (theFeatureID == SKETCH_ARC_KIND) { + else if (theFeatureID == SketchPlugin_Arc::ID()) { return FeaturePtr(new SketchPlugin_Arc); } - else if (theFeatureID == SKETCH_CONSTRAINT_COINCIDENCE_KIND) { + else if (theFeatureID == SketchPlugin_ConstraintCoincidence::ID()) { return FeaturePtr(new SketchPlugin_ConstraintCoincidence); } - else if (theFeatureID == SKETCH_CONSTRAINT_DISTANCE_KIND) { + else if (theFeatureID == SketchPlugin_ConstraintDistance::ID()) { return FeaturePtr(new SketchPlugin_ConstraintDistance); } - else if (theFeatureID == SKETCH_CONSTRAINT_LENGTH_KIND) { + else if (theFeatureID == SketchPlugin_ConstraintLength::ID()) { return FeaturePtr(new SketchPlugin_ConstraintLength); } - else if (theFeatureID == SKETCH_CONSTRAINT_PARALLEL_KIND) { + else if (theFeatureID == SketchPlugin_ConstraintParallel::ID()) { return FeaturePtr(new SketchPlugin_ConstraintParallel); } - else if (theFeatureID == SKETCH_CONSTRAINT_PERPENDICULAR_KIND) { + else if (theFeatureID == SketchPlugin_ConstraintPerpendicular::ID()) { return FeaturePtr(new SketchPlugin_ConstraintPerpendicular); } - else if (theFeatureID == SKETCH_CONSTRAINT_RADIUS_KIND) { + else if (theFeatureID == SketchPlugin_ConstraintRadius::ID()) { return FeaturePtr(new SketchPlugin_ConstraintRadius); } // feature of such kind is not found diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index 984d98919..fd60230de 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -20,7 +20,7 @@ SketchPlugin_Point::SketchPlugin_Point() void SketchPlugin_Point::initAttributes() { - data()->addAttribute(POINT_ATTR_COORD, GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::type()); } void SketchPlugin_Point::execute() @@ -33,7 +33,7 @@ const boost::shared_ptr& SketchPlugin_Point::preview() if (aSketch) { // compute a point in 3D view boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(data()->attribute(POINT_ATTR_COORD)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Point::COORD_ID())); boost::shared_ptr aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y())); // make a visible point boost::shared_ptr aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D); @@ -55,7 +55,7 @@ void SketchPlugin_Point::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(POINT_ATTR_COORD)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Point::COORD_ID())); aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); } @@ -63,7 +63,7 @@ double SketchPlugin_Point::distanceToPoint(const boost::shared_ptr aData = data(); boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(POINT_ATTR_COORD)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Point::COORD_ID())); return aPoint->pnt()->distance(thePoint); } diff --git a/src/SketchPlugin/SketchPlugin_Point.h b/src/SketchPlugin/SketchPlugin_Point.h index 31fad0ea4..f4bf4f6a7 100644 --- a/src/SketchPlugin/SketchPlugin_Point.h +++ b/src/SketchPlugin/SketchPlugin_Point.h @@ -10,12 +10,6 @@ #include "SketchPlugin_Feature.h" #include -/// Point feature kind -const std::string SKETCH_POINT_KIND("SketchPoint"); - -/// Coordinates of the point -const std::string POINT_ATTR_COORD("PointCoordindates"); - /**\class SketchPlugin_Point * \ingroup DataModel * \brief Feature for creation of a new point. @@ -23,13 +17,25 @@ const std::string POINT_ATTR_COORD("PointCoordindates"); class SketchPlugin_Point: public SketchPlugin_Feature { public: + /// Point feature kind + inline static const std::string& ID() + { + static const std::string MY_POINT_ID("SketchPoint"); + return MY_POINT_ID; + } + /// Coordinates of the point + inline static const std::string& COORD_ID() + { + static const std::string MY_COORD_ID("PointCoordindates"); + return MY_COORD_ID; + } /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = SKETCH_POINT_KIND; return MY_KIND;} + {static std::string MY_KIND = SketchPlugin_Point::ID(); 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 = SKETCH_KIND; return MY_GROUP;} + {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;} /// Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 7bc0ec600..b0bf6e9f6 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -28,11 +28,11 @@ SketchPlugin_Sketch::SketchPlugin_Sketch() void SketchPlugin_Sketch::initAttributes() { - data()->addAttribute(SKETCH_ATTR_ORIGIN, GeomDataAPI_Point::type()); - data()->addAttribute(SKETCH_ATTR_DIRX, GeomDataAPI_Dir::type()); - data()->addAttribute(SKETCH_ATTR_DIRY, GeomDataAPI_Dir::type()); - data()->addAttribute(SKETCH_ATTR_NORM, GeomDataAPI_Dir::type()); - data()->addAttribute(SKETCH_ATTR_FEATURES, ModelAPI_AttributeRefList::type()); + data()->addAttribute(SketchPlugin_Sketch::ORIGIN_ID(), GeomDataAPI_Point::type()); + data()->addAttribute(SketchPlugin_Sketch::DIRX_ID(), GeomDataAPI_Dir::type()); + data()->addAttribute(SketchPlugin_Sketch::DIRY_ID(), GeomDataAPI_Dir::type()); + data()->addAttribute(SketchPlugin_Sketch::NORM_ID(), GeomDataAPI_Dir::type()); + data()->addAttribute(SketchPlugin_Sketch::FEATURES_ID(), ModelAPI_AttributeRefList::type()); } void SketchPlugin_Sketch::execute() @@ -40,16 +40,16 @@ void SketchPlugin_Sketch::execute() if (!data()->isValid()) return ; boost::shared_ptr aRefList = - boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_FEATURES)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Sketch::FEATURES_ID())); boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_ORIGIN)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); boost::shared_ptr aDirX = - boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_DIRX)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Sketch::DIRX_ID())); boost::shared_ptr aDirY = - boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_DIRY)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Sketch::DIRY_ID())); boost::shared_ptr aNorm = - boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_NORM)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Sketch::NORM_ID())); std::list > aFeatures = aRefList->list(); if (aFeatures.empty()) @@ -109,7 +109,7 @@ const boost::shared_ptr& SketchPlugin_Sketch::preview() const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature) { boost::dynamic_pointer_cast(theFeature)->setSketch(this); - data()->reflist(SKETCH_ATTR_FEATURES)->append(theFeature); + data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(theFeature); } void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ, @@ -125,11 +125,11 @@ void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ, boost::shared_ptr SketchPlugin_Sketch::to3D(const double theX, const double theY) { boost::shared_ptr aC = - boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_ORIGIN)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); boost::shared_ptr aX = - boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_DIRX)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Sketch::DIRX_ID())); boost::shared_ptr aY = - boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_DIRY)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Sketch::DIRY_ID())); boost::shared_ptr aSum = aC->pnt()->xyz()->added( aX->dir()->xyz()->multiplied(theX))->added(aY->dir()->xyz()->multiplied(theY)); @@ -140,7 +140,7 @@ boost::shared_ptr SketchPlugin_Sketch::to3D(const double theX, cons bool SketchPlugin_Sketch::isPlaneSet() { boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_NORM)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Sketch::NORM_ID())); return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0); } @@ -148,9 +148,9 @@ bool SketchPlugin_Sketch::isPlaneSet() boost::shared_ptr SketchPlugin_Sketch::plane() { boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_ORIGIN)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); boost::shared_ptr aNorm = - boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_NORM)); + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Sketch::NORM_ID())); if (!anOrigin || !aNorm) return boost::shared_ptr(); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index d88267bed..5cde6adad 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -11,20 +11,6 @@ #include #include -/// Sketch feature kind -const std::string SKETCH_KIND("Sketch"); - -/// Origin point of the sketcher in 3D space -const std::string SKETCH_ATTR_ORIGIN("Origin"); -/// Vector X inside of the sketch plane -const std::string SKETCH_ATTR_DIRX("DirX"); -/// Vector Y inside of the sketch plane -const std::string SKETCH_ATTR_DIRY("DirY"); -/// Vector Z, normal to the sketch plane -const std::string SKETCH_ATTR_NORM("Norm"); -/// All features of this sketch (list of references) -const std::string SKETCH_ATTR_FEATURES("Features"); - /**\class SketchPlugin_Sketch * \ingroup DataModel * \brief Feature for creation of the new part in PartSet. @@ -32,9 +18,46 @@ const std::string SKETCH_ATTR_FEATURES("Features"); class SketchPlugin_Sketch: public SketchPlugin_Feature { public: + /// Sketch feature kind + inline static const std::string& ID() + { + static const std::string MY_SKETCH_ID("Sketch"); + return MY_SKETCH_ID; + } + /// Origin point of the sketcher in 3D space + inline static const std::string& ORIGIN_ID() + { + static const std::string MY_ORIGIN_ID("Origin"); + return MY_ORIGIN_ID; + } + /// Vector X inside of the sketch plane + inline static const std::string& DIRX_ID() + { + static const std::string MY_DIRX_ID("DirX"); + return MY_DIRX_ID; + } + /// Vector Y inside of the sketch plane + inline static const std::string& DIRY_ID() + { + static const std::string MY_DIRY_ID("DirY"); + return MY_DIRY_ID; + } + /// Vector Z, normal to the sketch plane + inline static const std::string& NORM_ID() + { + static const std::string MY_NORM_ID("Norm"); + return MY_NORM_ID; + } + /// All features of this sketch (list of references) + inline static const std::string& FEATURES_ID() + { + static const std::string MY_FEATURES_ID("Features"); + return MY_FEATURES_ID; + } + /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = SKETCH_KIND; return MY_KIND;} + {static std::string MY_KIND = SketchPlugin_Sketch::ID(); return MY_KIND;} /// Returns to which group in the document must be added feature SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 67a177038..18bd68e2b 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -60,7 +60,7 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr anAttr = boost::dynamic_pointer_cast( - theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr]) + theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)) ); if (!anAttr) continue; // Verify the attribute is a 2D point @@ -69,7 +69,7 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr anAttr = boost::dynamic_pointer_cast( - theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr]) + theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)) ); if (!anAttr) continue; if (anAttr->isFeature() && anAttr->feature()) { // verify posiible entities const std::string& aKind = anAttr->feature()->getKind(); - if (aKind.compare(SKETCH_POINT_KIND) == 0) + if (aKind.compare(SketchPlugin_Point::ID()) == 0) { - myAttributesList[aNbPoints++] = CONSTRAINT_ATTRIBUTES[indAttr]; + myAttributesList[aNbPoints++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); continue; } - else if(aKind.compare(SKETCH_LINE_KIND) == 0) + else if(aKind.compare(SketchPlugin_Line::ID()) == 0) { - // entities are placed starting from CONSTRAINT_ATTR_ENTITY_C attribute - myAttributesList[2 + aNbEntities++] = CONSTRAINT_ATTRIBUTES[indAttr]; + // entities are placed starting from SketchPlugin_Constraint::ENTITY_C() attribute + myAttributesList[2 + aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); myType = SLVS_C_PT_LINE_DISTANCE; continue; } @@ -127,7 +127,7 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr(anAttr->attr()); if (aPoint2D) { - myAttributesList[aNbPoints++] = CONSTRAINT_ATTRIBUTES[indAttr]; + myAttributesList[aNbPoints++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); continue; } // Verify the attribute is a 3D point @@ -135,7 +135,7 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr(anAttr->attr()); if (aPoint3D) { - myAttributesList[aNbPoints++] = CONSTRAINT_ATTRIBUTES[indAttr]; + myAttributesList[aNbPoints++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); continue; } } @@ -149,20 +149,20 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr anAttr = boost::dynamic_pointer_cast( - theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr]) + theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)) ); if (!anAttr) continue; if (anAttr->isFeature() && anAttr->feature() && - anAttr->feature()->getKind().compare(SKETCH_LINE_KIND) == 0) + anAttr->feature()->getKind().compare(SketchPlugin_Line::ID()) == 0) { - myAttributesList[aNbLines++] = CONSTRAINT_ATTRIBUTES[indAttr]; + myAttributesList[aNbLines++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); break; } } @@ -172,22 +172,22 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr anAttr = boost::dynamic_pointer_cast( - theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr]) + theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)) ); if (!anAttr || !anAttr->isFeature() || !anAttr->feature()) continue; const std::string& aKind = anAttr->feature()->getKind(); - if (aKind.compare(SKETCH_LINE_KIND) == 0) + if (aKind.compare(SketchPlugin_Line::ID()) == 0) { - myAttributesList[aNbEntities++] = CONSTRAINT_ATTRIBUTES[indAttr]; + myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); continue; } } @@ -197,20 +197,20 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr anAttr = boost::dynamic_pointer_cast( - theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr]) + theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)) ); if (!anAttr || !anAttr->isFeature() || !anAttr->feature()) continue; const std::string& aKind = anAttr->feature()->getKind(); - if (aKind.compare(SKETCH_CIRCLE_KIND) == 0 || aKind.compare(SKETCH_ARC_KIND) == 0) + if (aKind.compare(SketchPlugin_Circle::ID()) == 0 || aKind.compare(SketchPlugin_Arc::ID()) == 0) { - myAttributesList[aNbEntities++] = CONSTRAINT_ATTRIBUTES[indAttr]; + myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); continue; } } diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp index 2f7931f9b..d2f1dcc42 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp @@ -31,7 +31,20 @@ /// Tolerance for value of parameters const double tolerance = 1.e-10; -const std::string ERROR_SOLVE_CONSTRAINTS = "Conflicting constraints"; +/* + * Collects all sketch solver error' codes + * as inline static functions + * TODO: Move this class into a separate file + */ +class SketchSolver_Error { +public: + /// The value parameter for the constraint + inline static const std::string& CONSTRAINTS() + { + static const std::string MY_ERROR_VALUE("Conflicting constraints"); + return MY_ERROR_VALUE; + } +}; /// This value is used to give unique index to the groups static Slvs_hGroup myGroupIndexer = 0; @@ -118,7 +131,7 @@ bool SketchSolver_ConstraintGroup::isInteract( { boost::shared_ptr aCAttrRef = boost::dynamic_pointer_cast( - theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[i]) + theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(i)) ); if (!aCAttrRef) continue; if (!aCAttrRef->isFeature() && @@ -166,7 +179,7 @@ bool SketchSolver_ConstraintGroup::changeConstraint( // Create constraint parameters double aDistance = 0.0; // scalar value of the constraint AttributeDoublePtr aDistAttr = - boost::dynamic_pointer_cast(theConstraint->data()->attribute(CONSTRAINT_ATTR_VALUE)); + boost::dynamic_pointer_cast(theConstraint->data()->attribute(SketchPlugin_Constraint::VALUE())); if (aDistAttr) { aDistance = aDistAttr->value(); @@ -191,11 +204,11 @@ bool SketchSolver_ConstraintGroup::changeConstraint( if (!aConstrAttr) continue; // For the length constraint the start and end points of the line should be added to the entities list instead of line - if (aConstrType == SLVS_C_PT_PT_DISTANCE && theConstraint->getKind().compare(SKETCH_CONSTRAINT_LENGTH_KIND) == 0) + if (aConstrType == SLVS_C_PT_PT_DISTANCE && theConstraint->getKind().compare(SketchPlugin_ConstraintLength::ID()) == 0) { boost::shared_ptr aData = aConstrAttr->feature()->data(); - aConstrEnt[indAttr] = changeEntity(aData->attribute(LINE_ATTR_START)); - aConstrEnt[indAttr+1] = changeEntity(aData->attribute(LINE_ATTR_END)); + aConstrEnt[indAttr] = changeEntity(aData->attribute(SketchPlugin_Line::START_ID())); + aConstrEnt[indAttr+1] = changeEntity(aData->attribute(SketchPlugin_Line::END_ID())); myEntityFeatMap[aConstrAttr->feature()] = 0; // measured object is added into the map of objects to avoid problems with interaction betwee constraint and group break; // there should be no other entities } @@ -343,10 +356,10 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity( const std::string& aFeatureKind = aFeature->getKind(); // Line - if (aFeatureKind.compare(SKETCH_LINE_KIND) == 0) + if (aFeatureKind.compare(SketchPlugin_Line::ID()) == 0) { - Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(LINE_ATTR_START)); - Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(LINE_ATTR_END)); + Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(SketchPlugin_Line::START_ID())); + Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(SketchPlugin_Line::END_ID())); if (isEntExists) return aEntIter->second; @@ -358,10 +371,10 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity( return aLineEntity.h; } // Circle - else if (aFeatureKind.compare(SKETCH_CIRCLE_KIND) == 0) + else if (aFeatureKind.compare(SketchPlugin_Circle::ID()) == 0) { - Slvs_hEntity aCenter = changeEntity(aFeature->data()->attribute(CIRCLE_ATTR_CENTER)); - Slvs_hEntity aRadius = changeEntity(aFeature->data()->attribute(CIRCLE_ATTR_RADIUS)); + Slvs_hEntity aCenter = changeEntity(aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); + Slvs_hEntity aRadius = changeEntity(aFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID())); if (isEntExists) return aEntIter->second; @@ -374,11 +387,11 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity( return aCircleEntity.h; } // Arc - else if (aFeatureKind.compare(SKETCH_ARC_KIND) == 0) + else if (aFeatureKind.compare(SketchPlugin_Arc::ID()) == 0) { - Slvs_hEntity aCenter = changeEntity(aFeature->data()->attribute(ARC_ATTR_CENTER)); - Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(ARC_ATTR_START)); - Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(ARC_ATTR_END)); + Slvs_hEntity aCenter = changeEntity(aFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID())); + Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(SketchPlugin_Arc::START_ID())); + Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(SketchPlugin_Arc::END_ID())); if (isEntExists) return aEntIter->second; @@ -390,9 +403,9 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity( return anArcEntity.h; } // Point (it has low probability to be an attribute of constraint, so it is checked at the end) - else if (aFeatureKind.compare(SKETCH_POINT_KIND) == 0) + else if (aFeatureKind.compare(SketchPlugin_Point::ID()) == 0) { - Slvs_hEntity aPoint = changeEntity(aFeature->data()->attribute(POINT_ATTR_COORD)); + Slvs_hEntity aPoint = changeEntity(aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); if (isEntExists) return aEntIter->second; @@ -473,7 +486,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeNormal( bool SketchSolver_ConstraintGroup::addWorkplane( boost::shared_ptr theSketch) { - if (myWorkplane.h || theSketch->getKind().compare(SKETCH_KIND) != 0) + if (myWorkplane.h || theSketch->getKind().compare(SketchPlugin_Sketch::ID()) != 0) return false; // the workplane already exists or the function parameter is not Sketch mySketch = theSketch; @@ -489,10 +502,10 @@ bool SketchSolver_ConstraintGroup::addWorkplane( bool SketchSolver_ConstraintGroup::updateWorkplane() { // Get parameters of workplane - boost::shared_ptr aDirX = mySketch->data()->attribute(SKETCH_ATTR_DIRX); - boost::shared_ptr aDirY = mySketch->data()->attribute(SKETCH_ATTR_DIRY); - boost::shared_ptr aNorm = mySketch->data()->attribute(SKETCH_ATTR_NORM); - boost::shared_ptr anOrigin = mySketch->data()->attribute(SKETCH_ATTR_ORIGIN); + boost::shared_ptr aDirX = mySketch->data()->attribute(SketchPlugin_Sketch::DIRX_ID()); + boost::shared_ptr aDirY = mySketch->data()->attribute(SketchPlugin_Sketch::DIRY_ID()); + boost::shared_ptr aNorm = mySketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()); + boost::shared_ptr anOrigin = mySketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()); // Transform them into SolveSpace format Slvs_hEntity aNormalWP = changeNormal(aDirX, aDirY, aNorm); if (!aNormalWP) return false; @@ -570,7 +583,7 @@ void SketchSolver_ConstraintGroup::resolveConstraints() updateRelatedConstraints(anEntIter->first); } else if (!myConstraints.empty()) - Events_Error::send(ERROR_SOLVE_CONSTRAINTS, this); + Events_Error::send(SketchSolver_Error::CONSTRAINTS(), this); removeTemporaryConstraints(); myNeedToSolve = false; @@ -758,7 +771,7 @@ bool SketchSolver_ConstraintGroup::updateGroup() { if (!aConstrIter->first->data()->isValid()) { - if (aConstrIter->first->getKind().compare(SKETCH_CONSTRAINT_COINCIDENCE_KIND) == 0) + if (aConstrIter->first->getKind().compare(SketchPlugin_ConstraintCoincidence::ID()) == 0) isCCRemoved = true; std::map, Slvs_hConstraint>::reverse_iterator aCopyIter = aConstrIter++; diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index ff571878b..2976eca8f 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -76,7 +76,7 @@ void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessa { // Only sketches and constraints can be added by Create event const std::string& aFeatureKind = (*aFeatIter)->getKind(); - if (aFeatureKind.compare(SKETCH_KIND) == 0) + if (aFeatureKind.compare(SketchPlugin_Sketch::ID()) == 0) { boost::shared_ptr aSketch = boost::dynamic_pointer_cast(*aFeatIter); @@ -108,10 +108,10 @@ void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessa 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 + // Find SketchPlugin_Sketch::ID() in groups. The constraint groups should be updated when an object removed from Sketch std::set::const_iterator aFGrIter; for (aFGrIter = aFeatureGroups.begin(); aFGrIter != aFeatureGroups.end(); aFGrIter++) - if (aFGrIter->compare(SKETCH_KIND) == 0) + if (aFGrIter->compare(SketchPlugin_Sketch::ID()) == 0) break; if (aFGrIter != aFeatureGroups.end()) @@ -259,26 +259,26 @@ void SketchSolver_ConstraintManager::updateEntity(boost::shared_ptr anAttrList; const std::string& aFeatureKind = theFeature->getKind(); // Point - if (aFeatureKind.compare(SKETCH_POINT_KIND) == 0) - anAttrList.push_back(POINT_ATTR_COORD); + if (aFeatureKind.compare(SketchPlugin_Point::ID()) == 0) + anAttrList.push_back(SketchPlugin_Point::COORD_ID()); // Line - else if (aFeatureKind.compare(SKETCH_LINE_KIND) == 0) + else if (aFeatureKind.compare(SketchPlugin_Line::ID()) == 0) { - anAttrList.push_back(LINE_ATTR_START); - anAttrList.push_back(LINE_ATTR_END); + anAttrList.push_back(SketchPlugin_Line::START_ID()); + anAttrList.push_back(SketchPlugin_Line::END_ID()); } // Circle - else if (aFeatureKind.compare(SKETCH_CIRCLE_KIND) == 0) + else if (aFeatureKind.compare(SketchPlugin_Circle::ID()) == 0) { - anAttrList.push_back(CIRCLE_ATTR_CENTER); - anAttrList.push_back(CIRCLE_ATTR_RADIUS); + anAttrList.push_back(SketchPlugin_Circle::CENTER_ID()); + anAttrList.push_back(SketchPlugin_Circle::RADIUS_ID()); } // Arc - else if (aFeatureKind.compare(SKETCH_ARC_KIND) == 0) + else if (aFeatureKind.compare(SketchPlugin_Arc::ID()) == 0) { - anAttrList.push_back(ARC_ATTR_CENTER); - anAttrList.push_back(ARC_ATTR_START); - anAttrList.push_back(ARC_ATTR_END); + anAttrList.push_back(SketchPlugin_Arc::CENTER_ID()); + anAttrList.push_back(SketchPlugin_Arc::START_ID()); + anAttrList.push_back(SketchPlugin_Arc::END_ID()); } /// \todo Other types of features should be implemented @@ -350,7 +350,7 @@ boost::shared_ptr SketchSolver_ConstraintManager::findWork continue; boost::shared_ptr aWPFeatures = - boost::dynamic_pointer_cast(aWP->data()->attribute(SKETCH_ATTR_FEATURES)); + boost::dynamic_pointer_cast(aWP->data()->attribute(SketchPlugin_Sketch::FEATURES_ID())); std::list< FeaturePtr > aFeaturesList = aWPFeatures->list(); std::list< FeaturePtr >::const_iterator anIter; for (anIter = aFeaturesList.begin(); anIter != aFeaturesList.end(); anIter++) diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 8ecb179b3..58fb68090 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -105,7 +105,7 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const FeaturePtr aFeature = aFeatures.first(); //Process Feature if (aFeature) { - if (aFeature->getKind() == PARTSET_PART_KIND) { + if (aFeature->getKind() == PartSetPlugin_Part::ID()) { ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); DocumentPtr aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value(); if (aMgr->currentDocument() == aFeaDoc) diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index b4cc62c0c..a7d6c3c8b 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -56,7 +56,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) FeaturePtr aFeature = (*aIt); DocumentPtr aDoc = aFeature->document(); if (aDoc == aRootDoc) { // If root objects - if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { // Update only Parts group + if (aFeature->getGroup().compare(ModelAPI_Document::PARTS_GROUP()) == 0) { // Update only Parts group // Add a new part int aStart = myPartModels.size(); XGUI_PartDataModel* aModel = new XGUI_PartDataModel(this); @@ -96,7 +96,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) { std::string aGroup = (*aIt); if (aDoc == aRootDoc) { // If root objects - if (aGroup.compare(PARTS_GROUP) == 0) { // Updsate only Parts group + if (aGroup.compare(ModelAPI_Document::PARTS_GROUP()) == 0) { // Updsate only Parts group int aStart = myPartModels.size() - 1; removeSubModel(aStart); removeRow(aStart, partFolderNode()); @@ -151,7 +151,7 @@ void XGUI_DocumentDataModel::rebuildDataTree() beginResetModel(); clearModelIndexes(); - int aNbParts = aRootDoc->size(PARTS_GROUP); + int aNbParts = aRootDoc->size(ModelAPI_Document::PARTS_GROUP()); if (myPartModels.size() != aNbParts) { // resize internal models while (myPartModels.size() > aNbParts) { delete myPartModels.last(); @@ -192,7 +192,7 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) { int aOffset = historyOffset(); DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - FeaturePtr aFeature = aRootDoc->feature(FEATURES_GROUP, theIndex.row() - aOffset); + FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - aOffset); if (!aFeature) return QVariant(); switch (theRole) { @@ -236,7 +236,7 @@ int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const // Size of external models int aVal = historyOffset(); // Plus history size - aVal += aRootDoc->size(FEATURES_GROUP); + aVal += aRootDoc->size(ModelAPI_Document::FEATURES_GROUP()); return aVal; } if (theParent.internalId() == PartsFolder) { @@ -364,7 +364,7 @@ FeaturePtr XGUI_DocumentDataModel::feature(const QModelIndex& theIndex) const if (theIndex.internalId() == HistoryNode) { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); int aOffset = historyOffset(); - return aRootDoc->feature(FEATURES_GROUP, theIndex.row() - aOffset); + return aRootDoc->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - aOffset); } QModelIndex* aIndex = toSourceModelIndex(theIndex); if (!isSubModel(aIndex->model())) @@ -527,8 +527,8 @@ QModelIndex XGUI_DocumentDataModel::featureIndex(const FeaturePtr theFeature) co // This feature belongs to histrory or top model if (theFeature->isInHistory()) { int aId; - for (aId = 0; aId < aRootDoc->size(FEATURES_GROUP); aId++) { - if (theFeature == aRootDoc->feature(FEATURES_GROUP, aId)) + for (aId = 0; aId < aRootDoc->size(ModelAPI_Document::FEATURES_GROUP()); aId++) { + if (theFeature == aRootDoc->feature(ModelAPI_Document::FEATURES_GROUP(), aId)) break; } return index(aId + historyOffset(), 0, QModelIndex()); @@ -554,4 +554,4 @@ QModelIndex XGUI_DocumentDataModel::featureIndex(const FeaturePtr theFeature) co } } return QModelIndex(); -} \ No newline at end of file +} diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index ced60958b..82dcc8532 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -42,7 +42,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const case ParamObject: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - FeaturePtr aFeature = aRootDoc->feature(PARAMETERS_GROUP, theIndex.row()); + FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::PARAMETERS_GROUP(), theIndex.row()); if (aFeature) return boost::dynamic_pointer_cast(aFeature)->getName().c_str(); } @@ -51,7 +51,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const case ConstructObject: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - FeaturePtr aFeature = aRootDoc->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row()); if (aFeature) return boost::dynamic_pointer_cast(aFeature)->getName().c_str(); } @@ -68,7 +68,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const case ConstructObject: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - FeaturePtr aFeature = aRootDoc->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row()); if (aFeature) return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); } @@ -97,10 +97,10 @@ int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); if (theParent.internalId() == ParamsFolder) - return aRootDoc->size(PARAMETERS_GROUP); + return aRootDoc->size(ModelAPI_Document::PARAMETERS_GROUP()); if (theParent.internalId() == ConstructFolder) - return aRootDoc->size(CONSTRUCTIONS_GROUP); + return aRootDoc->size(ModelAPI_Document::CONSTRUCTIONS_GROUP()); return 0; } @@ -158,12 +158,12 @@ FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const case ParamObject: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - return aRootDoc->feature(PARAMETERS_GROUP, theIndex.row()); + return aRootDoc->feature(ModelAPI_Document::PARAMETERS_GROUP(), theIndex.row()); } case ConstructObject: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - return aRootDoc->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + return aRootDoc->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row()); } } return FeaturePtr(); @@ -177,9 +177,9 @@ QModelIndex XGUI_TopDataModel::findParent(const FeaturePtr& theFeature) const QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const { - if (theGroup.compare(PARAMETERS_GROUP) == 0) + if (theGroup.compare(ModelAPI_Document::PARAMETERS_GROUP()) == 0) return createIndex(0, 0, (qint32) ParamsFolder); - if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0) + if (theGroup.compare(ModelAPI_Document::CONSTRUCTIONS_GROUP()) == 0) return createIndex(1, 0, (qint32) ConstructFolder); return QModelIndex(); } @@ -199,9 +199,9 @@ QModelIndex XGUI_TopDataModel::featureIndex(const FeaturePtr& theFeature) const } } if (aRow != -1) { - if (aGroup.compare(PARAMETERS_GROUP) == 0) + if (aGroup.compare(ModelAPI_Document::PARAMETERS_GROUP()) == 0) return createIndex(aRow, 0, (qint32) ParamObject); - if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0) + if (aGroup.compare(ModelAPI_Document::CONSTRUCTIONS_GROUP()) == 0) return createIndex(aRow, 0, (qint32) ConstructObject); } } @@ -232,7 +232,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons case MyRoot: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - FeaturePtr aFeature = aRootDoc->feature(PARTS_GROUP, myId); + FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId); if (aFeature) return boost::dynamic_pointer_cast(aFeature)->getName().c_str(); } @@ -244,19 +244,19 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex)); case ParamObject: { - FeaturePtr aFeature = featureDocument()->feature(PARAMETERS_GROUP, theIndex.row()); + FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::PARAMETERS_GROUP(), theIndex.row()); if (aFeature) return boost::dynamic_pointer_cast(aFeature)->getName().c_str(); } case ConstructObject: { - FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row()); if (aFeature) return boost::dynamic_pointer_cast(aFeature)->getName().c_str(); } case HistoryObject: { - FeaturePtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); + FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - 3); if (aFeature) return aFeature->data()->getName().c_str(); } @@ -274,13 +274,13 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons return QIcon(":pictures/constr_folder.png"); case ConstructObject: { - FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row()); if (aFeature) return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); } case HistoryObject: { - FeaturePtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); + FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - 3); if (aFeature) return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); } @@ -305,18 +305,18 @@ int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const { if (!parent.isValid()) { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - if (aRootDoc->feature(PARTS_GROUP, myId)) + if (aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId)) return 1; else return 0; } switch (parent.internalId()) { case MyRoot: - return 3 + featureDocument()->size(FEATURES_GROUP); + return 3 + featureDocument()->size(ModelAPI_Document::FEATURES_GROUP()); case ParamsFolder: - return featureDocument()->size(PARAMETERS_GROUP); + return featureDocument()->size(ModelAPI_Document::PARAMETERS_GROUP()); case ConstructFolder: - return featureDocument()->size(CONSTRUCTIONS_GROUP); + return featureDocument()->size(ModelAPI_Document::CONSTRUCTIONS_GROUP()); case BodiesFolder: return 0; } @@ -383,7 +383,7 @@ bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const DocumentPtr XGUI_PartDataModel::featureDocument() const { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - FeaturePtr aFeature = aRootDoc->feature(PARTS_GROUP, myId, true); + FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId, true); return aFeature->data()->docRef("PartDocument")->value(); } @@ -393,20 +393,20 @@ FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const case MyRoot: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - return aRootDoc->feature(PARTS_GROUP, myId); + return aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId); } case ParamsFolder: case ConstructFolder: case BodiesFolder: return FeaturePtr(); case ParamObject: - return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row()); + return featureDocument()->feature(ModelAPI_Document::PARAMETERS_GROUP(), theIndex.row()); case ConstructObject: - return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + return featureDocument()->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row()); //case BodiesObject: - // return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + // return featureDocument()->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row()); case HistoryObject: - return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); + return featureDocument()->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - 3); } return FeaturePtr(); } @@ -424,9 +424,9 @@ QModelIndex XGUI_PartDataModel::findParent(const FeaturePtr& theFeature) const QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const { - if (theGroup.compare(PARAMETERS_GROUP) == 0) + if (theGroup.compare(ModelAPI_Document::PARAMETERS_GROUP()) == 0) return createIndex(0, 0, (qint32) ParamsFolder); - if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0) + if (theGroup.compare(ModelAPI_Document::CONSTRUCTIONS_GROUP()) == 0) return createIndex(1, 0, (qint32) ConstructFolder); return QModelIndex(); } @@ -434,7 +434,7 @@ QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const FeaturePtr XGUI_PartDataModel::part() const { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - return aRootDoc->feature(PARTS_GROUP, myId, true); + return aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId, true); } QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const @@ -446,10 +446,10 @@ QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const //std::string aGroup = theFeature->getGroup(); DocumentPtr aDoc = theFeature->document(); - int aNb = aDoc->size(FEATURES_GROUP); + int aNb = aDoc->size(ModelAPI_Document::FEATURES_GROUP()); int aRow = -1; for (int i = 0; i < aNb; i++) { - if (aDoc->feature(FEATURES_GROUP, i) == theFeature) { + if (aDoc->feature(ModelAPI_Document::FEATURES_GROUP(), i) == theFeature) { aRow = i; break; } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index b5b0b5f6b..1044a403a 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -296,7 +296,7 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const Model_FeatureUpdatedMessage* the bool isDisplayed = false; for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { FeaturePtr aFeature = (*aIt); - if (aFeature->getKind() != PARTSET_PART_KIND) { + if (aFeature->getKind() != PartSetPlugin_Part::ID()) { isDisplayed = myDisplayer->redisplay(aFeature, false); } } @@ -314,7 +314,7 @@ void XGUI_Workshop::onFeatureCreatedMsg(const Model_FeatureUpdatedMessage* theMs bool isDisplayed = false; for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { FeaturePtr aFeature = (*aIt); - if (aFeature->getKind() == PARTSET_PART_KIND) { + if (aFeature->getKind() == PartSetPlugin_Part::ID()) { aHasPart = true; //break; } else { @@ -903,7 +903,8 @@ void XGUI_Workshop::activateLastPart() { PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); DocumentPtr aDoc = aMgr->rootDocument(); - FeaturePtr aLastPart = aDoc->feature(PARTS_GROUP, aDoc->size(PARTS_GROUP) - 1, true); + FeaturePtr aLastPart = aDoc->feature(ModelAPI_Document::PARTS_GROUP(), + aDoc->size(ModelAPI_Document::PARTS_GROUP()) - 1, true); activatePart(aLastPart); } @@ -918,7 +919,7 @@ void XGUI_Workshop::deleteFeatures(QFeatureList theList) PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); aMgr->rootDocument()->startOperation(); foreach (FeaturePtr aFeature, theList) { - if (aFeature->getKind() == PARTSET_PART_KIND) { + if (aFeature->getKind() == PartSetPlugin_Part::ID()) { DocumentPtr aDoc; if (!XGUI_Tools::isModelObject(aFeature)) { aDoc = aFeature->data()->docRef("PartDocument")->value(); -- 2.39.2