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<ModelAPI_AttributeReference> aFaceRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(data()->attribute(EXTRUSION_FACE));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
if (!aFaceRef)
return;
FeaturePtr aFaceFeature = aFaceRef->value();
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));
}
#include "FeaturesPlugin.h"
#include <ModelAPI_Feature.h>
-/// 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()
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
boost::shared_ptr<ModelAPI_Document> 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
// 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());
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
string aName; // result
// iterate all features but also iterate group of this feature if object is not in history
list<string> aGroups;
- aGroups.push_back(FEATURES_GROUP);
+ aGroups.push_back(ModelAPI_Document::FEATURES_GROUP());
if (!theFeature->isInHistory()) {
aGroups.push_back(theFeature->getGroup());
}
// update features
vector<FeaturePtr >::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;
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
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<ModelAPI_Document> document()
// iterate all features of features-documents to update them
set<boost::shared_ptr<ModelAPI_Document> >::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<ModelAPI_Feature> aFeature = (*aDIter)->feature(FEATURES_GROUP, aFIndex);
+ boost::shared_ptr<ModelAPI_Feature> aFeature = (*aDIter)->feature(ModelAPI_Document::FEATURES_GROUP(), aFIndex);
if (aFeature)
updateFeature(aFeature);
}
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.
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
std::set<std::string>::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);
}
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<ModelAPI_Object>(aFeature);
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
{
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);
}
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();
}
}
if (!aData->isValid())
return std::list<FeaturePtr>();
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
return aRefList->list();
}
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
AttributeDoublePtr anAttr;
boost::shared_ptr<GeomDataAPI_Dir> aNormal =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
}
return aHasPlane;
boost::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
boost::shared_ptr<GeomDataAPI_Point> anOrigin =
- boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
anOrigin->setValue(anOrigPnt);
boost::shared_ptr<GeomDataAPI_Dir> aNormal =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
aNormal->setValue(aNormDir);
boost::shared_ptr<GeomDataAPI_Dir> aDirX =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
aDirX->setValue(aXDir);
boost::shared_ptr<GeomDataAPI_Dir> aDirY =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
aDirY->setValue(aYDir);
boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
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
if (aPreviewOp) {
// create a line
boost::shared_ptr<ModelAPI_Document> 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();
boost::dynamic_pointer_cast<SketchPlugin_Feature>(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<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
/*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<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
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<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
boost::shared_ptr<GeomAPI_AISObject> aPrevAIS;
boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
boost::shared_ptr<GeomDataAPI_Point> anOrigin =
- boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
boost::shared_ptr<GeomDataAPI_Dir> aX =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
boost::shared_ptr<GeomDataAPI_Dir> anY =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
gp_Pnt anOriginPnt(anOrigin->x(), anOrigin->y(), anOrigin->z());
gp_Vec aVec(anOriginPnt, thePoint);
anEyeVec.Normalize();
boost::shared_ptr<GeomDataAPI_Dir> aNormal =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
gp_Vec aNormalVec(aNormal->x(), aNormal->y(), aNormal->z());
double aDen = anEyeVec * aNormalVec;
boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
boost::shared_ptr<GeomDataAPI_Point> aC =
- boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
boost::shared_ptr<GeomDataAPI_Dir> aX =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
boost::shared_ptr<GeomDataAPI_Dir> aY =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
boost::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(
aX->dir()->xyz()->multiplied(theX))->added(aY->dir()->xyz()->multiplied(theY));
boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
{
boost::shared_ptr<ModelAPI_Document> aDoc = document();
- FeaturePtr aFeature = aDoc->addFeature(SKETCH_CONSTRAINT_COINCIDENCE_KIND);
+ FeaturePtr aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID());
if (theSketch) {
boost::shared_ptr<SketchPlugin_Feature> aSketch =
boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
aRef1->setAttr(thePoint1);
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
aRef2->setAttr(thePoint2);
if (aFeature) // TODO: generate an error if feature was not created
// the constraint is created between the feature point and the found sketch point
boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
std::list<FeaturePtr > aFeatures = aRefList->list();
std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
boost::shared_ptr<GeomDataAPI_Point> anOrigin =
- boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
boost::shared_ptr<GeomDataAPI_Dir> aNormal =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
aA = aNormal->x();
aB = aNormal->y();
aC = aNormal->z();
return aPoint;
boost::shared_ptr<GeomDataAPI_Point> aC =
- boost::dynamic_pointer_cast<GeomDataAPI_Point>(theSketch->data()->attribute(SKETCH_ATTR_ORIGIN));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
boost::shared_ptr<GeomDataAPI_Dir> aX =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theSketch->data()->attribute(SKETCH_ATTR_DIRX));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theSketch->data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
boost::shared_ptr<GeomDataAPI_Dir> aY =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theSketch->data()->attribute(SKETCH_ATTR_DIRY));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(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();
}
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<ModelAPI_AttributeRefAttr> aRef = data()->refattr(PART_DUPLICATE_ATTR_REF);
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef = data()->refattr(PartSetPlugin_Duplicate::DOC_REF());
if (!aRef->attr()) { // create a copy: if not created yet attribute is not initialized
boost::shared_ptr<ModelAPI_PluginManager> aPManager = ModelAPI_PluginManager::get();
boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
aSource = boost::dynamic_pointer_cast<PartSetPlugin_Part>(
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<ModelAPI_Document> 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);
}
}
#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.
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();
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<ModelAPI_AttributeDocRef> aDocRef = data()->docRef(PART_ATTR_DOC_REF);
+ boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->docRef(PartSetPlugin_Part::DOC_REF());
if (!aDocRef->value()) { // create a document if not yet created
boost::shared_ptr<ModelAPI_Document> aPartSetDoc =
ModelAPI_PluginManager::get()->rootDocument();
#include "PartSetPlugin.h"
#include <ModelAPI_Feature.h>
-/// 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.
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()
FeaturePtr PartSetPlugin_Plugin::createFeature(string theFeatureID)
{
- if (theFeatureID == PARTSET_PART_KIND) {
+ if (theFeatureID == PartSetPlugin_Part::ID()) {
return FeaturePtr(new PartSetPlugin_Part);
}
if (theFeatureID == "duplicate") {
boost::shared_ptr<PartSetPlugin_Part> 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<PartSetPlugin_Part> aPart =
boost::static_pointer_cast<PartSetPlugin_Part>(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);
}
}
#include "PartSetPlugin.h"
#include <ModelAPI_Feature.h>
-/// Extrusion kind
-const std::string PARTSET_REMOVE_KIND("Remove");
-
/**\class PartSetPlugin_Remove
* \ingroup DataModel
* \brief Feature for creation of the new part in PartSet.
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()
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()
// compute a circle point in 3D view
boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_CENTER));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::CENTER_ID()));
// compute the arc start point
boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_START));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID()));
if (aCenterAttr->isInitialized() && aStartAttr->isInitialized()) {
boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
// make a visible point
// make a visible circle
boost::shared_ptr<GeomDataAPI_Dir> aNDir =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->data()->attribute(SKETCH_ATTR_NORM));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
if (aHasPlane) {
boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
// compute and change the arc end point
boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_END));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::END_ID()));
if (anEndAttr->isInitialized())
{
boost::shared_ptr<GeomAPI_Circ2d> aCircleForArc(
return;
boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Arc::CENTER_ID()));
aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Arc::START_ID()));
aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY);
boost::shared_ptr<GeomDataAPI_Point2D> aPoint3 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Arc::END_ID()));
aPoint3->setValue(aPoint3->x() + theDeltaX, aPoint3->y() + theDeltaY);
}
boost::shared_ptr<ModelAPI_Data> aData = data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Arc::CENTER_ID()));
aDelta = aPoint1->pnt()->distance(thePoint);
boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Arc::START_ID()));
double aDistance = aPoint2->pnt()->distance(thePoint);
if (aDelta < aDistance)
aDelta = aDistance;
boost::shared_ptr<GeomDataAPI_Point2D> aPoint3 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Arc::END_ID()));
aDistance = aPoint3->pnt()->distance(thePoint);
if (aDelta < aDistance)
aDelta = aDistance;
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
-/// 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.
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();
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()
// compute a circle point in 3D view
boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CIRCLE_ATTR_CENTER));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Circle::CENTER_ID()));
AttributeDoublePtr aRadiusAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CIRCLE_ATTR_RADIUS));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Circle::RADIUS_ID()));
if (aCenterAttr->isInitialized() && aRadiusAttr->isInitialized()) {
boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
// make a visible point
// make a visible circle
boost::shared_ptr<GeomDataAPI_Dir> aNDir =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->data()->attribute(SKETCH_ATTR_NORM));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
if (aHasPlane) {
boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
return;
boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Circle::CENTER_ID()));
aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
}
{
boost::shared_ptr<ModelAPI_Data> aData = data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Circle::CENTER_ID()));
return aPoint->pnt()->distance(thePoint);
}
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
-/// 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.
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();
*
* 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
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
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()
#include <SketchPlugin_Sketch.h>
#include <list>
-/// 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();
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<ModelAPI_Data> aData = data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_A);
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_B);
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
if (aPoint_A && aPoint_B) {
AttributeDoublePtr anAttr_Value =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
if (!anAttr_Value->isInitialized()) {
anAttr_Value->setValue(aPoint_A->pnt()->distance(aPoint_B->pnt()));
boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
DataPtr aData = data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_A);
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_B);
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
if (!aPoint_A || !aPoint_B)
return thePrevious;
boost::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPoint_A->x(), aPoint_A->y());
boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPoint_B->x(), aPoint_B->y());
// value calculation
boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
double aValue = aValueAttr->value();
boost::shared_ptr<GeomAPI_AISObject> anAIS = thePrevious;
return;
boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
}
if (anAttr)
aFeature = anAttr->feature();
- if (aFeature && aFeature->getKind() == SKETCH_POINT_KIND)
+ if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
- (aFeature->data()->attribute(POINT_ATTR_COORD));
+ (aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
else {
if (anAttr->attr())
aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
#include <SketchPlugin_Sketch.h>
#include <list>
-/// 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();
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<ModelAPI_AttributeRefAttr> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
FeaturePtr aFeature = aRef->feature();
if (aFeature) {
// set length value
boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(LINE_ATTR_START));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(SketchPlugin_Line::START_ID()));
boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(LINE_ATTR_END));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(SketchPlugin_Line::END_ID()));
double aLenght = aPoint1->pnt()->distance(aPoint2->pnt());
boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_VALUE));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
aValueAttr->setValue(aLenght);
}
}
boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(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<GeomDataAPI_Point2D> aFlyOutAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
DataPtr aData = aFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::START_ID()));
boost::shared_ptr<GeomDataAPI_Point2D> anEndPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aStartPoint->x(), aStartPoint->y());
boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(anEndPoint->x(), anEndPoint->y());
// value calculation
boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_VALUE));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
double aValue = aValueAttr->value();
boost::shared_ptr<GeomAPI_AISObject> anAIS = thePrevious;
return;
boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
}
#include <SketchPlugin_Sketch.h>
#include <list>
-/// 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();
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()
boost::shared_ptr<ModelAPI_Data> aData = data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
if (!anAttr1 || !anAttr1->isFeature() ||
!anAttr2 || !anAttr2->isFeature())
return thePrevious;
boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
boost::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
boost::shared_ptr<GeomAPI_AISObject> anAIS = thePrevious;
return;
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);
}
#include <SketchPlugin_Sketch.h>
#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();
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()
boost::shared_ptr<ModelAPI_Data> aData = data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
if (!anAttr1 || !anAttr1->isFeature() ||
!anAttr2 || !anAttr2->isFeature())
return thePrevious;
return;
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);
}
#include <SketchPlugin_Sketch.h>
#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();
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<ModelAPI_AttributeRefAttr> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
FeaturePtr aFeature = aRef->feature();
if (aFeature) {
double aRadius = 0;
boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
- if (aFeature->getKind() == SKETCH_CIRCLE_KIND) {
+ if (aFeature->getKind() == SketchPlugin_Circle::ID()) {
AttributeDoublePtr anAttribute = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>
- (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<GeomDataAPI_Point2D> aCenterAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Arc::CENTER_ID()));
boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Arc::START_ID()));
if (aCenterAttr && aStartAttr)
aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
}
boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_VALUE));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
aValueAttr->setValue(aRadius);
}
}
boost::shared_ptr<ModelAPI_Data> aData = data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(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<GeomDataAPI_Point2D> aFlyoutAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
if (!aFlyoutAttr->isInitialized())
return thePrevious;
boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
aData = aFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
double aRadius;
- if (aKind == SKETCH_CIRCLE_KIND) {
- aCenterAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
+ if (aKind == SketchPlugin_Circle::ID()) {
+ aCenterAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Circle::CENTER_ID()));
AttributeDoublePtr aCircRadius =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CIRCLE_ATTR_RADIUS));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Circle::RADIUS_ID()));
aRadius = aCircRadius->value();
}
- else if (aKind == SKETCH_ARC_KIND) {
- aCenterAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
+ else if (aKind == SketchPlugin_Arc::ID()) {
+ aCenterAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Arc::CENTER_ID()));
boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Arc::START_ID()));
aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
}
boost::shared_ptr<GeomAPI_Pnt> aCenter = sketch()->to3D(aCenterAttr->x(), aCenterAttr->y());
boost::shared_ptr<GeomDataAPI_Dir> aNDir =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(sketch()->data()->attribute(SKETCH_ATTR_NORM));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(sketch()->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
boost::shared_ptr<GeomAPI_Circ> aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius));
// Value
boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
double aValue = aRadius;
if (aValueAttr && aValueAttr->isInitialized())
aValue = aValueAttr->value();
return;
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(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<GeomDataAPI_Point2D> aCenterAttr =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(aCenterAttrName));
boost::shared_ptr<GeomAPI_Pnt2d> aCenter = aCenterAttr->pnt();
// The specified delta applied on the circle curve,
// so it will be scaled due to distance between flyout and center points
boost::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
boost::shared_ptr<GeomAPI_Pnt2d> aFlyout = aFlyoutAttr->pnt();
boost::shared_ptr<ModelAPI_AttributeDouble> aRadius =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
double aScale = aFlyout->distance(aCenter) / aRadius->value();
boost::shared_ptr<GeomAPI_Circ2d> aCircle(new GeomAPI_Circ2d(aCenter, aFlyout));
#include <SketchPlugin_Sketch.h>
#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();
dynamic_pointer_cast<SketchPlugin_Sketch>(document()->feature("Construction", a, true));
if (aSketch) {
std::list<FeaturePtr > aList =
- aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
+ aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
std::list<FeaturePtr >::iterator aSub = aList.begin();
for(; aSub != aList.end(); aSub++) {
if ((*aSub)->data()->isEqual(data())) {
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()
if (aSketch) {
// compute a start point in 3D view
boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(LINE_ATTR_START));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Line::START_ID()));
// compute an end point in 3D view
boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(LINE_ATTR_END));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Line::END_ID()));
if (aStartAttr->isInitialized() && anEndAttr->isInitialized()) {
boost::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
boost::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
return;
boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::START_ID()));
aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY);
}
boost::shared_ptr<ModelAPI_Data> aData = data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::START_ID()));
boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y());
#include <SketchPlugin_Sketch.h>
#include <list>
-/// 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.
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();
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
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()
if (aSketch) {
// compute a point in 3D view
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(POINT_ATTR_COORD));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Point::COORD_ID()));
boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
// make a visible point
boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
return;
boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Point::COORD_ID()));
aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
}
{
boost::shared_ptr<ModelAPI_Data> aData = data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Point::COORD_ID()));
return aPoint->pnt()->distance(thePoint);
}
#include "SketchPlugin_Feature.h"
#include <list>
-/// 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.
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();
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()
if (!data()->isValid())
return ;
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(SKETCH_ATTR_FEATURES));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(SketchPlugin_Sketch::FEATURES_ID()));
boost::shared_ptr<GeomDataAPI_Point> anOrigin =
- boost::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(SKETCH_ATTR_ORIGIN));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
boost::shared_ptr<GeomDataAPI_Dir> aDirX =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_DIRX));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
boost::shared_ptr<GeomDataAPI_Dir> aDirY =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_DIRY));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
boost::shared_ptr<GeomDataAPI_Dir> aNorm =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_NORM));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SketchPlugin_Sketch::NORM_ID()));
std::list<boost::shared_ptr<ModelAPI_Feature> > aFeatures = aRefList->list();
if (aFeatures.empty())
const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature)
{
boost::dynamic_pointer_cast<SketchPlugin_Feature>(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,
boost::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
{
boost::shared_ptr<GeomDataAPI_Point> aC =
- boost::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(SKETCH_ATTR_ORIGIN));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
boost::shared_ptr<GeomDataAPI_Dir> aX =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_DIRX));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
boost::shared_ptr<GeomDataAPI_Dir> aY =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_DIRY));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
boost::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(
aX->dir()->xyz()->multiplied(theX))->added(aY->dir()->xyz()->multiplied(theY));
bool SketchPlugin_Sketch::isPlaneSet()
{
boost::shared_ptr<GeomDataAPI_Dir> aNormal =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_NORM));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SketchPlugin_Sketch::NORM_ID()));
return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
}
boost::shared_ptr<GeomAPI_Pln> SketchPlugin_Sketch::plane()
{
boost::shared_ptr<GeomDataAPI_Point> anOrigin =
- boost::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(SKETCH_ATTR_ORIGIN));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
boost::shared_ptr<GeomDataAPI_Dir> aNorm =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_NORM));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SketchPlugin_Sketch::NORM_ID()));
if (!anOrigin || !aNorm)
return boost::shared_ptr<GeomAPI_Pln>();
#include <GeomAPI_Pln.h>
#include <list>
-/// 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.
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()
{
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr])
+ theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr))
);
if (!anAttr) continue;
// Verify the attribute is a 2D point
if (aPoint2D)
{
aPt2d |= (1 << indAttr);
- myAttributesList[anAttrPos++] = CONSTRAINT_ATTRIBUTES[indAttr];
+ myAttributesList[anAttrPos++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
continue;
}
// Verify the attribute is a 3D point
if (aPoint3D)
{
aPt3d |= (1 << indAttr);
- myAttributesList[anAttrPos++] = CONSTRAINT_ATTRIBUTES[indAttr];
+ myAttributesList[anAttrPos++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
continue;
}
// Attribute neither 2D nor 3D point is not supported by this type of constraint
}
// Constraint for distance between point and another entity
- if (aConstraintKind.compare(SKETCH_CONSTRAINT_DISTANCE_KIND) == 0)
+ if (aConstraintKind.compare(SketchPlugin_ConstraintDistance::ID()) == 0)
{
int aNbPoints = 0;
int aNbEntities = 0;
{
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- 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;
}
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
if (aPoint2D)
{
- myAttributesList[aNbPoints++] = CONSTRAINT_ATTRIBUTES[indAttr];
+ myAttributesList[aNbPoints++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
continue;
}
// Verify the attribute is a 3D point
boost::dynamic_pointer_cast<GeomDataAPI_Point>(anAttr->attr());
if (aPoint3D)
{
- myAttributesList[aNbPoints++] = CONSTRAINT_ATTRIBUTES[indAttr];
+ myAttributesList[aNbPoints++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
continue;
}
}
}
// Constraint for the given length of a line
- if (aConstraintKind.compare(SKETCH_CONSTRAINT_LENGTH_KIND) == 0)
+ if (aConstraintKind.compare(SketchPlugin_ConstraintLength::ID()) == 0)
{
int aNbLines = 0;
for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++)
{
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- 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;
}
}
}
// Constraint for two parallel/perpendicular lines
- bool isParallel = (aConstraintKind.compare(SKETCH_CONSTRAINT_PARALLEL_KIND) == 0);
- bool isPerpendicular = (aConstraintKind.compare(SKETCH_CONSTRAINT_PERPENDICULAR_KIND) == 0);
+ bool isParallel = (aConstraintKind.compare(SketchPlugin_ConstraintParallel::ID()) == 0);
+ bool isPerpendicular = (aConstraintKind.compare(SketchPlugin_ConstraintPerpendicular::ID()) == 0);
if (isParallel || isPerpendicular)
{
- int aNbEntities = 2; // lines in SolveSpace constraints should started from CONSTRAINT_ATTR_ENTITY_C attribute
+ int aNbEntities = 2; // lines in SolveSpace constraints should started from SketchPlugin_Constraint::ENTITY_C() attribute
for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++)
{
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- 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;
}
}
}
// Constraint for radius of a circle or an arc of circle
- if (aConstraintKind.compare(SKETCH_CONSTRAINT_RADIUS_KIND) == 0)
+ if (aConstraintKind.compare(SketchPlugin_ConstraintRadius::ID()) == 0)
{
- int aNbEntities = 2; // lines in SolveSpace constraints should started from CONSTRAINT_ATTR_ENTITY_C attribute
+ int aNbEntities = 2; // lines in SolveSpace constraints should started from SketchPlugin_Constraint::ENTITY_C() attribute
for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++)
{
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- 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;
}
}
/// 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;
{
boost::shared_ptr<ModelAPI_AttributeRefAttr> aCAttrRef =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[i])
+ theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(i))
);
if (!aCAttrRef) continue;
if (!aCAttrRef->isFeature() &&
// Create constraint parameters
double aDistance = 0.0; // scalar value of the constraint
AttributeDoublePtr aDistAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theConstraint->data()->attribute(CONSTRAINT_ATTR_VALUE));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theConstraint->data()->attribute(SketchPlugin_Constraint::VALUE()));
if (aDistAttr)
{
aDistance = aDistAttr->value();
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<ModelAPI_Data> 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
}
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;
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;
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;
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;
bool SketchSolver_ConstraintGroup::addWorkplane(
boost::shared_ptr<SketchPlugin_Feature> 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;
bool SketchSolver_ConstraintGroup::updateWorkplane()
{
// Get parameters of workplane
- boost::shared_ptr<ModelAPI_Attribute> aDirX = mySketch->data()->attribute(SKETCH_ATTR_DIRX);
- boost::shared_ptr<ModelAPI_Attribute> aDirY = mySketch->data()->attribute(SKETCH_ATTR_DIRY);
- boost::shared_ptr<ModelAPI_Attribute> aNorm = mySketch->data()->attribute(SKETCH_ATTR_NORM);
- boost::shared_ptr<ModelAPI_Attribute> anOrigin = mySketch->data()->attribute(SKETCH_ATTR_ORIGIN);
+ boost::shared_ptr<ModelAPI_Attribute> aDirX = mySketch->data()->attribute(SketchPlugin_Sketch::DIRX_ID());
+ boost::shared_ptr<ModelAPI_Attribute> aDirY = mySketch->data()->attribute(SketchPlugin_Sketch::DIRY_ID());
+ boost::shared_ptr<ModelAPI_Attribute> aNorm = mySketch->data()->attribute(SketchPlugin_Sketch::NORM_ID());
+ boost::shared_ptr<ModelAPI_Attribute> anOrigin = mySketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID());
// Transform them into SolveSpace format
Slvs_hEntity aNormalWP = changeNormal(aDirX, aDirY, aNorm);
if (!aNormalWP) return false;
updateRelatedConstraints(anEntIter->first);
}
else if (!myConstraints.empty())
- Events_Error::send(ERROR_SOLVE_CONSTRAINTS, this);
+ Events_Error::send(SketchSolver_Error::CONSTRAINTS(), this);
removeTemporaryConstraints();
myNeedToSolve = false;
{
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<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::reverse_iterator
aCopyIter = aConstrIter++;
{
// 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<SketchPlugin_Feature> aSketch =
boost::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
dynamic_cast<const ModelAPI_FeatureDeletedMessage*>(theMessage);
const std::set<std::string>& 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<std::string>::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())
std::vector<std::string> 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
continue;
boost::shared_ptr<ModelAPI_AttributeRefList> aWPFeatures =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aWP->data()->attribute(SKETCH_ATTR_FEATURES));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(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++)
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<ModelAPI_Object>(aFeature);
DocumentPtr aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value();
if (aMgr->currentDocument() == aFeaDoc)
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);
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());
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();
{
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) {
// 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) {
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()))
// 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());
}
}
return QModelIndex();
-}
\ No newline at end of file
+}
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<ModelAPI_Object>(aFeature)->getName().c_str();
}
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<ModelAPI_Object>(aFeature)->getName().c_str();
}
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()));
}
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;
}
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();
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();
}
}
}
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);
}
}
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<ModelAPI_Object>(aFeature)->getName().c_str();
}
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<ModelAPI_Object>(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<ModelAPI_Object>(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();
}
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()));
}
{
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;
}
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();
}
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();
}
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();
}
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
//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;
}
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);
}
}
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 {
{
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);
}
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();