From: vsv Date: Wed, 6 Aug 2014 13:42:11 +0000 (+0400) Subject: Create validator for distance constraint X-Git-Tag: V_0.4.4~116 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3ce4e2cad0e6802282a5a1d10c49c041e8a9f287;p=modules%2Fshaper.git Create validator for distance constraint --- diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h index b557e845e..9866616cc 100644 --- a/src/GeomAPI/GeomAPI_Shape.h +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -28,6 +28,7 @@ public: /// Returns whether the shape is an edge virtual bool isEdge() const; + }; #endif diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index fdfb04ccf..45c3db890 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -18,6 +18,7 @@ SET(PROJECT_HEADERS Model_ResultBody.h Model_ResultConstruction.h Model_ResultPart.h + Model_ResultValidators.h ) SET(PROJECT_SOURCES @@ -37,6 +38,7 @@ SET(PROJECT_SOURCES Model_ResultBody.cpp Model_ResultConstruction.cpp Model_ResultPart.cpp + Model_ResultValidators.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/Model/Model_ResultValidators.cpp b/src/Model/Model_ResultValidators.cpp new file mode 100644 index 000000000..75b603fc7 --- /dev/null +++ b/src/Model/Model_ResultValidators.cpp @@ -0,0 +1,84 @@ +// File: Model_ResultValidators.cpp +// Created: 23 July 2014 +// Author: Vitaly SMETANNIKOV + +#include "Model_ResultValidators.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + + +ResultPtr result(const ObjectPtr theObject) +{ + return boost::dynamic_pointer_cast(theObject); +} + +TopoDS_Shape shape(ResultPtr theResult) +{ + boost::shared_ptr aShape = ModelAPI_Tools::shape(theResult); + if (aShape) + return aShape->impl(); + return TopoDS_Shape(); +} + + +bool Model_ResultPointValidator::isValid(const ObjectPtr theObject) const +{ + ResultPtr aResult = result(theObject); + if (!aResult) + return false; + TopoDS_Shape aShape = shape(aResult); + if (aShape.IsNull()) + return false; + + return aShape.ShapeType() == TopAbs_VERTEX; +} + + +bool Model_ResultLineValidator::isValid(const ObjectPtr theObject) const +{ + ResultPtr aResult = result(theObject); + if (!aResult) + return false; + TopoDS_Shape aShape = shape(aResult); + if (aShape.IsNull()) + return false; + + if (aShape.ShapeType() == TopAbs_EDGE) { + TopoDS_Edge aEdge = TopoDS::Edge(aShape); + Standard_Real aStart, aEnd; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd); + GeomAdaptor_Curve aAdaptor(aCurve); + return aAdaptor.GetType() == GeomAbs_Line; + } + return false; +} + + +bool Model_ResultArcValidator::isValid(const ObjectPtr theObject) const +{ + ResultPtr aResult = result(theObject); + if (!aResult) + return false; + TopoDS_Shape aShape = shape(aResult); + if (aShape.IsNull()) + return false; + + TopAbs_ShapeEnum aa = aShape.ShapeType(); + if (aShape.ShapeType() == TopAbs_EDGE) { + TopoDS_Edge aEdge = TopoDS::Edge(aShape); + Standard_Real aStart, aEnd; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd); + GeomAdaptor_Curve aAdaptor(aCurve); + return aAdaptor.GetType() == GeomAbs_Circle; + } + return false; +} + diff --git a/src/Model/Model_ResultValidators.h b/src/Model/Model_ResultValidators.h new file mode 100644 index 000000000..c76cd3056 --- /dev/null +++ b/src/Model/Model_ResultValidators.h @@ -0,0 +1,30 @@ +// File: Model_ResultValidators.h +// Created: 23 July 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef Model_ResultValidators_H +#define Model_ResultValidators_H + +#include "Model.h" +#include +#include + +class Model_ResultPointValidator: public ModelAPI_ResultValidator +{ +public: + MODEL_EXPORT virtual bool isValid(const ObjectPtr theObject) const; +}; + +class Model_ResultLineValidator: public ModelAPI_ResultValidator +{ +public: + MODEL_EXPORT virtual bool isValid(const ObjectPtr theObject) const; +}; + +class Model_ResultArcValidator: public ModelAPI_ResultValidator +{ +public: + MODEL_EXPORT virtual bool isValid(const ObjectPtr theObject) const; +}; + +#endif \ No newline at end of file diff --git a/src/Model/Model_Validator.cpp b/src/Model/Model_Validator.cpp index 77af27b99..19e9f56dd 100644 --- a/src/Model/Model_Validator.cpp +++ b/src/Model/Model_Validator.cpp @@ -3,6 +3,7 @@ // Author: Mikhail PONIKAROV #include +#include #include #include @@ -90,4 +91,17 @@ void Model_ValidatorsFactory::validators(const std::string& theFeatureID, Model_ValidatorsFactory::Model_ValidatorsFactory() : ModelAPI_ValidatorsFactory() { + registerValidator("Model_ResultPointValidator", new Model_ResultPointValidator); + registerValidator("Model_ResultLineValidator", new Model_ResultLineValidator); + registerValidator("Model_ResultArcValidator", new Model_ResultArcValidator); } + + +const ModelAPI_Validator* Model_ValidatorsFactory::validator(const std::string& theID) const +{ + std::map::const_iterator aIt = myIDs.find(theID); + if (aIt != myIDs.end()) { + return aIt->second; + } + return NULL; +} \ No newline at end of file diff --git a/src/Model/Model_Validator.h b/src/Model/Model_Validator.h index f1cfe24fc..45ad05c14 100644 --- a/src/Model/Model_Validator.h +++ b/src/Model/Model_Validator.h @@ -55,6 +55,9 @@ public: std::list& theValidators, std::list >& theArguments) const; + /// Returns registered validator by its Id + virtual const ModelAPI_Validator* validator(const std::string& theID) const; + /// Returns the result of "validate" method for attribute of validator. /// If validator is not exists, returns true: everything is valid by default. //MODEL_EXPORT virtual bool validate( diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 4d10c9ce1..cc1596c0f 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -26,11 +26,15 @@ SET(PROJECT_HEADERS ModelAPI_ResultConstruction.h ModelAPI_ResultPart.h ModelAPI_ResultParameters.h + ModelAPI_ResultValidator.h + ModelAPI_AttributeValidator.h + ModelAPI_Tools.h ) SET(PROJECT_SOURCES ModelAPI_Feature.cpp ModelAPI_PluginManager.cpp + ModelAPI_Tools.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModelAPI/ModelAPI_AttributeValidator.h b/src/ModelAPI/ModelAPI_AttributeValidator.h new file mode 100644 index 000000000..b40c145e2 --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeValidator.h @@ -0,0 +1,21 @@ +// File: ModelAPI_AttributeValidator.h +// Created: 5 Aug 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef ModelAPI_AttributeValidator_H +#define ModelAPI_AttributeValidator_H + +#include +#include +#include + + +class ModelAPI_AttributeValidator: public ModelAPI_Validator +{ +public: + virtual bool isValid(const FeaturePtr& theFeature, + const std::list& theArguments, + const ObjectPtr& theObject) const = 0; +}; + +#endif diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 5617cedd9..028f17385 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -5,6 +5,7 @@ #include "ModelAPI_Feature.h" #include #include +#include #include const std::list >& ModelAPI_Feature::results() @@ -70,3 +71,16 @@ ModelAPI_Feature::~ModelAPI_Feature() ModelAPI_EventCreator::get()->sendDeleted(aRes->document(), aRes->groupName()); } } + +FeaturePtr ModelAPI_Feature::feature(ObjectPtr theObject) +{ + FeaturePtr aFeature = boost::dynamic_pointer_cast(theObject); + if (!aFeature) { + ResultPtr aResult = boost::dynamic_pointer_cast(theObject); + if (aResult) { + DocumentPtr aDoc = aResult->document(); + return aDoc->feature(aResult); + } + } + return aFeature; +} diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index b42266074..a1d048af3 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -62,6 +62,9 @@ public: /// To virtually destroy the fields of successors MODELAPI_EXPORT virtual ~ModelAPI_Feature(); + + MODELAPI_EXPORT static boost::shared_ptr feature(ObjectPtr theObject); + }; //! Pointer on feature object diff --git a/src/ModelAPI/ModelAPI_ResultValidator.h b/src/ModelAPI/ModelAPI_ResultValidator.h new file mode 100644 index 000000000..7484246d1 --- /dev/null +++ b/src/ModelAPI/ModelAPI_ResultValidator.h @@ -0,0 +1,18 @@ +// File: ModelAPI_ResultValidators.h +// Created: 23 July 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef ModelAPI_ResultValidators_H +#define ModelAPI_ResultValidators_H + +#include "ModelAPI_Validator.h" +#include "ModelAPI_Object.h" + +class ModelAPI_ResultValidator: public ModelAPI_Validator +{ +public: + virtual bool isValid(const ObjectPtr theObject) const = 0; +}; + + +#endif \ No newline at end of file diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp new file mode 100644 index 000000000..1c49c6779 --- /dev/null +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -0,0 +1,21 @@ +// File: ModelAPI_Tools.cpp +// Created: 06 Aug 2014 +// Author: Vitaly Smetannikov + +#include "ModelAPI_Tools.h" +#include +#include + + +namespace ModelAPI_Tools { + +boost::shared_ptr shape(const ResultPtr& theResult) +{ + ResultBodyPtr aBody = boost::dynamic_pointer_cast(theResult); + if (aBody) return aBody->shape(); + ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast(theResult); + if (aConstruct) return aConstruct->shape(); + return boost::shared_ptr(); +} + +} \ No newline at end of file diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h new file mode 100644 index 000000000..f4fc0ebf0 --- /dev/null +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -0,0 +1,18 @@ +// File: ModelAPI_Tools.h +// Created: 06 Aug 2014 +// Author: Vitaly Smetannikov + +#ifndef ModelAPI_Tools_HeaderFile +#define ModelAPI_Tools_HeaderFile + +#include "ModelAPI.h" +#include +#include + +namespace ModelAPI_Tools +{ + /// Returns shape from the given Result object + MODELAPI_EXPORT boost::shared_ptr shape(const ResultPtr& theResult); +}; + +#endif \ No newline at end of file diff --git a/src/ModelAPI/ModelAPI_Validator.h b/src/ModelAPI/ModelAPI_Validator.h index 4f17e634c..88ab1574c 100644 --- a/src/ModelAPI/ModelAPI_Validator.h +++ b/src/ModelAPI/ModelAPI_Validator.h @@ -73,6 +73,9 @@ public: std::list& theValidators, std::list >& theArguments) const = 0; + /// Returns registered validator by its Id + virtual const ModelAPI_Validator* validator(const std::string& theID) const = 0; + /// Returns the result of "validate" method for attribute of validator. /// If validator is not exists, returns true: everything is valid by default. //virtual bool validate( diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 4c3f20caa..b21756a5c 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -25,9 +25,6 @@ SET(PROJECT_HEADERS ModuleBase_SelectionValidator.h ModuleBase_ISelection.h ModuleBase_ViewerPrs.h - ModuleBase_Tools.h - ModuleBase_ResultValidators.h - ModuleBase_FeatureValidator.h ) SET(PROJECT_SOURCES @@ -47,8 +44,6 @@ SET(PROJECT_SOURCES ModuleBase_WidgetPoint2dDistance.cpp ModuleBase_WidgetValue.cpp ModuleBase_WidgetValueFeature.cpp - ModuleBase_Tools.cpp - ModuleBase_ResultValidators.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModuleBase/ModuleBase_FeatureValidator.h b/src/ModuleBase/ModuleBase_FeatureValidator.h deleted file mode 100644 index ccbcca6e5..000000000 --- a/src/ModuleBase/ModuleBase_FeatureValidator.h +++ /dev/null @@ -1,20 +0,0 @@ -// File: ModuleBase_FeatureValidator.h -// Created: 8 Jul 2014 -// Author: Vitaly SMETANNIKOV - -#ifndef ModuleBase_FeatureValidator_H -#define ModuleBase_FeatureValidator_H - -#include "ModuleBase.h" - -#include -#include - - -class ModuleBase_FeatureValidator: public ModelAPI_Validator -{ -public: - virtual bool isValid(const FeaturePtr theFeature) const = 0; -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index de0548b3d..c150d01b3 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -14,7 +14,6 @@ #include class Config_WidgetAPI; -class ModelAPI_Feature; class ModuleBase_WidgetValue; class QKeyEvent; @@ -49,9 +48,9 @@ public: /// Saves the internal parameters to the given feature /// \param theObject a model feature to be changed - virtual bool storeValue(ObjectPtr theObject) const = 0; + virtual bool storeValue() const = 0; - virtual bool restoreValue(ObjectPtr theObject) = 0; + virtual bool restoreValue() = 0; /// Set focus to the first control of the current widget. The focus policy of the control is checked. /// If the widget has the NonFocus focus policy, it is skipped. @@ -74,6 +73,9 @@ public: /// \returns the string value std::string parentID() const { return myParentId; } + FeaturePtr feature() const { return myFeature;} + void setFeature(const FeaturePtr& theFeature) { myFeature = theFeature; } + signals: /// The signal about widget values changed void valuesChanged(); @@ -94,9 +96,10 @@ protected: bool myHasDefaultValue; /// the boolean state whether the control has a default value -private: + std::string myAttributeID; /// the attribute name of the model feature std::string myParentId; /// name of parent + FeaturePtr myFeature; }; #endif diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 44eddb349..4a980a1dc 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -9,7 +9,6 @@ #include "ModuleBase_OperationDescription.h" #include "ModuleBase_ModelWidget.h" -#include "ModuleBase_FeatureValidator.h" #include #include @@ -62,7 +61,7 @@ void ModuleBase_Operation::storeCustomValue() ModuleBase_ModelWidget* aCustom = dynamic_cast(sender()); if (aCustom) - aCustom->storeValue(myFeature); + aCustom->storeValue(); } void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget) @@ -97,7 +96,7 @@ void ModuleBase_Operation::afterCommitOperation() bool ModuleBase_Operation::canBeCommitted() const { if (ModuleBase_IOperation::canBeCommitted()) { - FeaturePtr aFeature = feature(); +/* FeaturePtr aFeature = feature(); std::string aId = aFeature->getKind(); PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); @@ -112,7 +111,7 @@ bool ModuleBase_Operation::canBeCommitted() const if (!aFValidator->isValid(aFeature)) return false; } - } + }*/ return true; } return false; diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 7da2d12ad..87f636360 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -11,27 +11,6 @@ namespace ModuleBase_Tools { //****************************************************************** -boost::shared_ptr shape(ResultPtr theResult) -{ - ResultBodyPtr aBody = boost::dynamic_pointer_cast(theResult); - if (aBody) return aBody->shape(); - ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast(theResult); - if (aConstruct) return aConstruct->shape(); - return boost::shared_ptr(); -} //****************************************************************** -FeaturePtr feature(ObjectPtr theObject) -{ - FeaturePtr aFeature = boost::dynamic_pointer_cast(theObject); - if (!aFeature) { - ResultPtr aResult = boost::dynamic_pointer_cast(theObject); - if (aResult) { - DocumentPtr aDoc = aResult->document(); - return aDoc->feature(aResult); - } - } - return aFeature; -} - } diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp index c77ecad44..07a8eb000 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp @@ -42,21 +42,21 @@ QWidget* ModuleBase_WidgetBoolValue::getControl() const return myCheckBox; } -bool ModuleBase_WidgetBoolValue::storeValue(ObjectPtr theObject) const +bool ModuleBase_WidgetBoolValue::storeValue() const { - DataPtr aData = theObject->data(); + DataPtr aData = myFeature->data(); boost::shared_ptr aBool = aData->boolean(attributeID()); if (aBool->value() != myCheckBox->isChecked()) { aBool->setValue(myCheckBox->isChecked()); - updateObject(theObject); + updateObject(myFeature); } return true; } -bool ModuleBase_WidgetBoolValue::restoreValue(ObjectPtr theObject) +bool ModuleBase_WidgetBoolValue::restoreValue() { - DataPtr aData = theObject->data(); + DataPtr aData = myFeature->data(); boost::shared_ptr aRef = aData->boolean(attributeID()); bool isBlocked = myCheckBox->blockSignals(true); diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.h b/src/ModuleBase/ModuleBase_WidgetBoolValue.h index 17c5a6849..7f6c822a8 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.h +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.h @@ -25,9 +25,9 @@ public: /// Saves the internal parameters to the given feature /// \param theObject a model feature to be changed - virtual bool storeValue(ObjectPtr theObject) const; + virtual bool storeValue() const; - virtual bool restoreValue(ObjectPtr theObject); + virtual bool restoreValue(); /// Returns list of widget controls /// \return a control list diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 97782bf74..beb384bcd 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -90,20 +90,20 @@ ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue() { } -bool ModuleBase_WidgetDoubleValue::storeValue(ObjectPtr theObject) const +bool ModuleBase_WidgetDoubleValue::storeValue() const { - DataPtr aData = theObject->data(); + DataPtr aData = myFeature->data(); AttributeDoublePtr aReal = aData->real(attributeID()); if (aReal->value() != mySpinBox->value()) { aReal->setValue(mySpinBox->value()); - updateObject(theObject); + updateObject(myFeature); } return true; } -bool ModuleBase_WidgetDoubleValue::restoreValue(ObjectPtr theObject) +bool ModuleBase_WidgetDoubleValue::restoreValue() { - DataPtr aData = theObject->data(); + DataPtr aData = myFeature->data(); AttributeDoublePtr aRef = aData->real(attributeID()); bool isBlocked = mySpinBox->blockSignals(true); diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h index a04a4e928..15b9063b3 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -26,9 +26,9 @@ public: /// Saves the internal parameters to the given feature /// \param theObject a model feature to be changed - virtual bool storeValue(ObjectPtr theObject) const; + virtual bool storeValue() const; - virtual bool restoreValue(ObjectPtr theObject); + virtual bool restoreValue(); /// Returns list of widget controls /// \return a control list diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.cpp b/src/ModuleBase/ModuleBase_WidgetFeature.cpp index 47e9960be..983329b53 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeature.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeature.cpp @@ -6,20 +6,20 @@ #include #include -#include -#include #include #include #include -#include +#include #include #include #include #include #include +#include +#include #include #include @@ -31,10 +31,6 @@ ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent, const std::string& theParentId) : ModuleBase_ModelWidget(theParent, theData, theParentId) { - //QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE)); - //myObjectKinds = aKinds.split(" "); - //theData-> - myContainer = new QWidget(theParent); QHBoxLayout* aControlLay = new QHBoxLayout(myContainer); aControlLay->setContentsMargins(0, 0, 0, 0); @@ -80,11 +76,13 @@ bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject, bool theSen std::list aValidators; std::list > anArguments; aFactory->validators(parentID(), attributeID(), aValidators, anArguments); + + // Check the type of selected object std::list::iterator aValidator = aValidators.begin(); bool isValid = true; for(; aValidator != aValidators.end(); aValidator++) { - const ModuleBase_ResultValidator* aResValidator = - dynamic_cast(*aValidator); + const ModelAPI_ResultValidator* aResValidator = + dynamic_cast(*aValidator); if (aResValidator) { isValid = false; if (aResValidator->isValid(theObject)) { @@ -96,35 +94,49 @@ bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject, bool theSen if (!isValid) return false; - myObject = ModuleBase_Tools::feature(theObject); + // Check the acceptability of the object as attribute + aValidator = aValidators.begin(); + std::list >::iterator aArgs = anArguments.begin(); + for(; aValidator != aValidators.end(); aValidator++, aArgs++) { + const ModelAPI_AttributeValidator* aAttrValidator = + dynamic_cast(*aValidator); + if (aAttrValidator) { + if (!aAttrValidator->isValid(myFeature, *aArgs, theObject)) { + return false; + } + } + } + + myObject = theObject; myEditor->setText(theObject ? theObject->data()->name().c_str() : ""); if (theSendEvent) emit valuesChanged(); return true; } -bool ModuleBase_WidgetFeature::storeValue(ObjectPtr theObject) const +bool ModuleBase_WidgetFeature::storeValue() const { - FeaturePtr aFeature = boost::dynamic_pointer_cast(theObject); - if (!aFeature) - return false; - boost::shared_ptr aData = aFeature->data(); + //FeaturePtr aFeature = boost::dynamic_pointer_cast(theObject); + //if (!aFeature) + // return false; + boost::shared_ptr aData = myFeature->data(); boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(attributeID())); ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this; aRef->setObject(myObject); - aFeature->execute(); - updateObject(theObject); + myFeature->execute(); + updateObject(myFeature); return true; } -bool ModuleBase_WidgetFeature::restoreValue(ObjectPtr theObject) +bool ModuleBase_WidgetFeature::restoreValue() { - boost::shared_ptr aData = theObject->data(); + boost::shared_ptr aData = myFeature->data(); boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(attributeID())); + ObjectPtr aObj = aRef->object(); FeaturePtr aFeature = boost::dynamic_pointer_cast(aRef->object()); if (aFeature) { myObject = aFeature; diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.h b/src/ModuleBase/ModuleBase_WidgetFeature.h index 81720edab..fee570d64 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeature.h +++ b/src/ModuleBase/ModuleBase_WidgetFeature.h @@ -40,9 +40,9 @@ public: /// Saves the internal parameters to the given feature /// \param theFeature a model feature to be changed - virtual bool storeValue(ObjectPtr theObject) const; + virtual bool storeValue() const; - virtual bool restoreValue(ObjectPtr theObject); + virtual bool restoreValue(); /// Returns the internal parent wiget control, that can be shown anywhere /// \returns the widget diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp index 525d24356..40fb3a52f 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -18,6 +17,8 @@ #include #include #include +#include + #include #include @@ -54,7 +55,7 @@ bool ModuleBase_WidgetFeatureOrAttribute::setValue(ModuleBase_WidgetValue* theVa isDone = setObject(aObject, false); } if (aValuePoint) { - FeaturePtr aFeature = ModuleBase_Tools::feature(aObject); + FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); if (aFeature) { // find the given point in the feature attributes std::list > anAttiributes = @@ -79,13 +80,13 @@ bool ModuleBase_WidgetFeatureOrAttribute::setValue(ModuleBase_WidgetValue* theVa return isDone; } -bool ModuleBase_WidgetFeatureOrAttribute::storeValue(ObjectPtr theFeature) const +bool ModuleBase_WidgetFeatureOrAttribute::storeValue() const { - FeaturePtr aFeature = boost::dynamic_pointer_cast(theFeature); - if (!aFeature) - return false; + //FeaturePtr aFeature = boost::dynamic_pointer_cast(theFeature); + //if (!aFeature) + // return false; - boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aData = myFeature->data(); boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(attributeID())); @@ -94,19 +95,20 @@ bool ModuleBase_WidgetFeatureOrAttribute::storeValue(ObjectPtr theFeature) const if (myAttribute) aRef->setAttr(myAttribute); - aFeature->execute(); - updateObject(theFeature); + myFeature->execute(); + updateObject(myFeature); return true; } -bool ModuleBase_WidgetFeatureOrAttribute::restoreValue(ObjectPtr theFeature) +bool ModuleBase_WidgetFeatureOrAttribute::restoreValue() { - boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aData = myFeature->data(); boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(attributeID())); - FeaturePtr aFeature = ModuleBase_Tools::feature(aRef->object()); + ObjectPtr aObj = aRef->object(); + FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object()); if (aFeature) { myObject = aFeature; myAttribute = aRef->attr(); diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h index 9de6c149a..0518409bd 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h +++ b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h @@ -36,9 +36,9 @@ public: /// Saves the internal parameters to the given feature /// \param theFeature a model feature to be changed - virtual bool storeValue(ObjectPtr theFeature) const; + virtual bool storeValue() const; - virtual bool restoreValue(ObjectPtr theFeature); + virtual bool restoreValue(); protected: /// Set the attribute diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index c9c3dd9c7..cd88c57b7 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -102,24 +102,24 @@ void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr& emit valuesChanged(); } -bool ModuleBase_WidgetPoint2D::storeValue(ObjectPtr theObject) const +bool ModuleBase_WidgetPoint2D::storeValue() const { - boost::shared_ptr aData = theObject->data(); + boost::shared_ptr aData = myFeature->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(attributeID())); ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this; bool isBlocked = that->blockSignals(true); aPoint->setValue(myXSpin->value(), myYSpin->value()); - updateObject(theObject); + updateObject(myFeature); that->blockSignals(isBlocked); return true; } -bool ModuleBase_WidgetPoint2D::restoreValue(ObjectPtr theObject) +bool ModuleBase_WidgetPoint2D::restoreValue() { - boost::shared_ptr aData = theObject->data(); + boost::shared_ptr aData = myFeature->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(attributeID())); diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.h b/src/ModuleBase/ModuleBase_WidgetPoint2D.h index ed249c4b7..77fbd74ee 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.h +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.h @@ -40,9 +40,9 @@ public: /// Saves the internal parameters to the given feature /// \param theObject a model feature to be changed - virtual bool storeValue(ObjectPtr theObject) const; + virtual bool storeValue() const; - virtual bool restoreValue(ObjectPtr theObject); + virtual bool restoreValue(); /// Returns the internal parent wiget control, that can be shown anywhere /// \returns the widget diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 8cb33574b..c0933f566 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -5,10 +5,10 @@ #include "ModuleBase_WidgetSelector.h" #include "ModuleBase_IWorkshop.h" -#include "ModuleBase_Tools.h" #include #include +#include #include #include @@ -102,28 +102,28 @@ ModuleBase_WidgetSelector::~ModuleBase_WidgetSelector() } //******************************************************************** -bool ModuleBase_WidgetSelector::storeValue(ObjectPtr theObject) const +bool ModuleBase_WidgetSelector::storeValue() const { - FeaturePtr aSelectedFeature = ModuleBase_Tools::feature(mySelectedObject); - if (aSelectedFeature == theObject) // In order to avoid selection of the same object + FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject); + if (aSelectedFeature == myFeature) // In order to avoid selection of the same object return false; - DataPtr aData = theObject->data(); + DataPtr aData = myFeature->data(); boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(attributeID())); ObjectPtr aObject = aRef->value(); if (!(aObject && aObject->isSame(mySelectedObject))) { aRef->setValue(mySelectedObject); - updateObject(theObject); + updateObject(myFeature); } return true; } //******************************************************************** -bool ModuleBase_WidgetSelector::restoreValue(ObjectPtr theObject) +bool ModuleBase_WidgetSelector::restoreValue() { - DataPtr aData = theObject->data(); + DataPtr aData = myFeature->data(); boost::shared_ptr aRef = aData->reference(attributeID()); bool isBlocked = this->blockSignals(true); @@ -174,7 +174,7 @@ void ModuleBase_WidgetSelector::onSelectionChanged() bool ModuleBase_WidgetSelector::isAccepted(const ObjectPtr theResult) const { ResultPtr aResult = boost::dynamic_pointer_cast(theResult); - boost::shared_ptr aShapePtr = ModuleBase_Tools::shape(aResult); + boost::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); if (!aShapePtr) return false; TopoDS_Shape aShape = aShapePtr->impl(); if (aShape.IsNull()) return false; diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index 1388bc773..9d7180848 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -34,9 +34,9 @@ public: /// Saves the internal parameters to the given feature /// \param theObject a model feature to be changed - virtual bool storeValue(ObjectPtr theObject) const; + virtual bool storeValue() const; - virtual bool restoreValue(ObjectPtr theObject); + virtual bool restoreValue(); /// Returns the internal parent wiget control, that can be shown anywhere /// \returns the widget diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 160f63f2e..ecace8c28 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -288,7 +287,7 @@ void PartSet_Module::onFitAllView() void PartSet_Module::onLaunchOperation(std::string theName, ObjectPtr theObject) { - FeaturePtr aFeature = ModuleBase_Tools::feature(theObject); + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); if (!aFeature) { qDebug("Warning! Restart operation without feature!"); return; diff --git a/src/PartSet/PartSet_OperationFeatureEdit.cpp b/src/PartSet/PartSet_OperationFeatureEdit.cpp index 32f0a86e2..887ec4f9c 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.cpp +++ b/src/PartSet/PartSet_OperationFeatureEdit.cpp @@ -11,15 +11,14 @@ #include #include #include -#include #include #include #include + #include #include - #include #include @@ -80,7 +79,7 @@ void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3 if (!aObject && !theSelected.empty()) // changed for a constrain aObject = theSelected.front().object(); - FeaturePtr aFeature = ModuleBase_Tools::feature(aObject); + FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); if (!aFeature || aFeature != feature()) { if (commit()) { emit featureConstructed(feature(), FM_Deactivation); diff --git a/src/PartSet/PartSet_OperationFeatureEditMulti.cpp b/src/PartSet/PartSet_OperationFeatureEditMulti.cpp index 30796c5fb..83d2a04b5 100644 --- a/src/PartSet/PartSet_OperationFeatureEditMulti.cpp +++ b/src/PartSet/PartSet_OperationFeatureEditMulti.cpp @@ -8,7 +8,6 @@ #include #include -#include #include @@ -60,7 +59,7 @@ void PartSet_OperationFeatureEditMulti::initSelection(const std::list::const_iterator anIt = theSelected.begin(), aLast = theSelected.end(); for (; anIt != aLast && !isSelected; anIt++) { - isSelected = ModuleBase_Tools::feature((*anIt).object()) == feature(); + isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature(); } if (!isSelected) myFeatures = theHighlighted; @@ -114,7 +113,7 @@ void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle ObjectPtr aObject = (*anIt).object(); if (!aObject || aObject == feature()) continue; - FeaturePtr aFeature = ModuleBase_Tools::feature(aObject); + FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); if (aFeature) { aSketchFeature = boost::dynamic_pointer_cast(aFeature); if (aSketchFeature) diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 558747b46..98cae8a48 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -25,9 +25,9 @@ public: /// Saves the internal parameters to the given feature /// \param theFeature a model feature to be changed - virtual bool storeValue(ObjectPtr theFeature) const { return true;} + virtual bool storeValue() const { return true;} - virtual bool restoreValue(ObjectPtr theFeature) { return true;} + virtual bool restoreValue() { return true;} /// Returns list of widget controls /// \return a control list diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index c731f49ea..d45087849 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -57,7 +57,6 @@ INCLUDE_DIRECTORIES( ../GeomAPI ../GeomAlgoAPI ../GeomDataAPI - ../ModuleBase ) INSTALL(TARGETS SketchPlugin DESTINATION plugins) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 531f09bd6..de504f56e 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -14,16 +14,6 @@ #include #include -/// Obtain the point object from specified constraint parameter -static boost::shared_ptr getFeaturePoint( - DataPtr theData, - const std::string& theAttribute); - -static boost::shared_ptr getFeatureLine(DataPtr theData, const std::string& theAttribute); - -static boost::shared_ptr getProjectionPoint(const boost::shared_ptr& theLine, - const boost::shared_ptr& thePoint); - SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance() { @@ -153,7 +143,7 @@ boost::shared_ptr getFeaturePoint(DataPtr theData, boost::shared_ptr anAttr = boost::dynamic_pointer_cast(theData->attribute(theAttribute)); if (anAttr) - aFeature = SketchPlugin_Sketch::getFeature(anAttr->object()); + aFeature = ModelAPI_Feature::feature(anAttr->object()); if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) aPointAttr = boost::dynamic_pointer_cast @@ -177,7 +167,7 @@ boost::shared_ptr getFeatureLine(DataPtr theData, const std:: boost::shared_ptr anAttr = boost::dynamic_pointer_cast(theData->attribute(theAttribute)); if (anAttr) { - FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(anAttr->object()); + FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object()); if (aFeature && aFeature->getKind() == SketchPlugin_Line::ID()) { aLine = boost::dynamic_pointer_cast(aFeature); } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index 3aed4ba9e..6a229544d 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -8,9 +8,13 @@ #include "SketchPlugin.h" #include "SketchPlugin_Constraint.h" #include "SketchPlugin_Sketch.h" +#include "ModelAPI_Data.h" #include +class SketchPlugin_Line; +class GeomDataAPI_Point2D; + /** \class SketchPlugin_ConstraintDistance * \ingroup DataModel * \brief Feature for creation of a new constraint which defines a distance @@ -52,4 +56,15 @@ public: SketchPlugin_ConstraintDistance(); }; + +/// Obtain the point object from specified constraint parameter +boost::shared_ptr getFeaturePoint(DataPtr theData, + const std::string& theAttribute); + +boost::shared_ptr getFeatureLine(DataPtr theData, const std::string& theAttribute); + +boost::shared_ptr getProjectionPoint(const boost::shared_ptr& theLine, + const boost::shared_ptr& thePoint); + + #endif diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index 3c2b146b8..28d2cf7d3 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -36,7 +36,7 @@ void SketchPlugin_ConstraintLength::execute() boost::shared_ptr aRef = boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); - FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(aRef->object()); + FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object()); if (aFeature) { // set length value boost::shared_ptr aPoint1 = @@ -65,7 +65,7 @@ boost::shared_ptr SketchPlugin_ConstraintLength::getAISObject boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); if (!anAttr) return thePrevious; - FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(anAttr->object()); + FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object()); if (!aFeature || aFeature->getKind() != SketchPlugin_Line::ID()) return thePrevious; diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp index 4a971e8c7..e2cd9c53d 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp @@ -45,13 +45,13 @@ boost::shared_ptr SketchPlugin_ConstraintParallel::getAISObje !anAttr2 || !anAttr2->isObject()) return thePrevious; - FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(anAttr1->object()); + FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object()); if (!aFeature) return thePrevious; boost::shared_ptr aLine1Feature = boost::dynamic_pointer_cast(aFeature); - aFeature = SketchPlugin_Sketch::getFeature(anAttr2->object()); + aFeature = ModelAPI_Feature::feature(anAttr2->object()); if (!aFeature) return thePrevious; boost::shared_ptr aLine2Feature = diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp index 8985eb061..4f6a0b771 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp @@ -45,13 +45,13 @@ boost::shared_ptr SketchPlugin_ConstraintPerpendicular::getAI !anAttr2 || !anAttr2->isObject()) return thePrevious; - FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(anAttr1->object()); + FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object()); if (!aFeature) return thePrevious; boost::shared_ptr aLine1Feature = boost::dynamic_pointer_cast(aFeature); - aFeature = SketchPlugin_Sketch::getFeature(anAttr2->object()); + aFeature = ModelAPI_Feature::feature(anAttr2->object()); if (!aFeature) return thePrevious; boost::shared_ptr aLine2Feature = diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index 11071843f..b77103542 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -37,7 +37,7 @@ void SketchPlugin_ConstraintRadius::execute() boost::shared_ptr aRef = boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); - FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(aRef->object()); + FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object()); if (aFeature) { double aRadius = 0; boost::shared_ptr aData = aFeature->data(); @@ -73,7 +73,7 @@ boost::shared_ptr SketchPlugin_ConstraintRadius::getAISObject boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); if (!anAttr) return thePrevious; - FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(anAttr->object()); + FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object()); std::string aKind = aFeature ? aFeature->getKind() : ""; if (aKind != SketchPlugin_Circle::ID() && aKind != SketchPlugin_Arc::ID()) return thePrevious; @@ -130,7 +130,7 @@ void SketchPlugin_ConstraintRadius::move(double theDeltaX, double theDeltaY) boost::shared_ptr aRef = boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); - FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(aRef->object()); + FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object()); if (!aFeature) return; std::string aCenterAttrName; diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 8c9de8767..2a05d4564 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -24,6 +24,7 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() { PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + aFactory->registerValidator("SketchPlugin_DistanceAttrValidator", new SketchPlugin_DistanceAttrValidator); // register this plugin ModelAPI_PluginManager::get()->registerPlugin(this); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index b2541dd8e..b3cacc6ae 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -167,16 +167,3 @@ boost::shared_ptr SketchPlugin_Sketch:: } return boost::shared_ptr(); } - -FeaturePtr SketchPlugin_Sketch::getFeature(ObjectPtr theObject) -{ - FeaturePtr aFeature = boost::dynamic_pointer_cast(theObject); - if (!aFeature) { - ResultPtr aResult = boost::dynamic_pointer_cast(theObject); - if (aResult) { - DocumentPtr aDoc = aResult->document(); - return aDoc->feature(aResult); - } - } - return aFeature; -} \ No newline at end of file diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 374f8a9e1..8a1d22db4 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -96,8 +96,6 @@ public: virtual boost::shared_ptr getAISObject( boost::shared_ptr thePrevious); - static FeaturePtr getFeature(ObjectPtr theObject); - protected: /// Creates a plane and append it to the list /// \param theX the X normal value diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 161a1442c..862a30344 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -3,55 +3,33 @@ // Author: Vitaly SMETANNIKOV #include "SketchPlugin_Validators.h" -#include "SketchPlugin_Constraint.h" -#include "SketchPlugin_Sketch.h" -#include "SketchPlugin_Point.h" -#include "SketchPlugin_Line.h" -#include "SketchPlugin_Circle.h" -#include "SketchPlugin_Arc.h" +#include "SketchPlugin_ConstraintDistance.h" #include +#include +#include +#include -bool isValidType(const std::string& theType) +bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature, + const std::list& theArguments, + const ObjectPtr& theObject) const { - return (theType == SketchPlugin_Point::ID()) || - (theType == SketchPlugin_Circle::ID()) || - (theType == SketchPlugin_Arc::ID()); + std::string aParamA = theArguments.front(); + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + + // If the object is not a line then it is accepted + const ModelAPI_ResultValidator* aLineValidator = dynamic_cast( + aFactory->validator("Model_ResultLineValidator")); + if (!aLineValidator->isValid(theObject)) + return true; + + // If it is a line then we have to check that first attribute id not a line + boost::shared_ptr aPoint = getFeaturePoint(theFeature->data(), aParamA); + if (aPoint) + return true; + return false; } -bool SketchPlugin_DistanceFeatureValidator::isValid(const FeaturePtr theFeature) const -{ - if (!theFeature) - return false; - if (!theFeature->data() || !theFeature->data()->isValid()) - return false; - boost::shared_ptr aData = theFeature->data(); - - boost::shared_ptr aRefA = - boost::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Constraint::ENTITY_A())); - - boost::shared_ptr aRefB = - boost::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Constraint::ENTITY_B())); - - if (!aRefA || !aRefB) - return false; - - return true; -/* FeaturePtr aFetureA = SketchPlugin_Sketch::getFeature(aRefA->object()); - FeaturePtr aFetureB = SketchPlugin_Sketch::getFeature(aRefB->object()); - if (!aFetureA || !aFetureB) - return false; - - std::string aTypeA = aFetureA->getKind(); - std::string aTypeB = aFetureB->getKind(); - - if (aTypeA == SketchPlugin_Line::ID()) { - return isValidType(aTypeB); - } else if (aTypeB == SketchPlugin_Line::ID()) { - return isValidType(aTypeA); - } else - return isValidType(aTypeA) && isValidType(aTypeB); - return false;*/ -} + + diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index 2941485cf..74357d1eb 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -6,14 +6,17 @@ #define SketchPlugin_Validators_H #include "SketchPlugin.h" -#include +//#include +#include -//! A class to validate a selection for Perpendicular constraint operation -class SketchPlugin_DistanceFeatureValidator: public ModuleBase_FeatureValidator +class SketchPlugin_DistanceAttrValidator: public ModelAPI_AttributeValidator { public: - SKETCHPLUGIN_EXPORT virtual bool isValid(const FeaturePtr theFeature) const; + virtual bool isValid(const FeaturePtr& theFeature, + const std::list& theArguments, + const ObjectPtr& theObject) const; + }; #endif \ No newline at end of file diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index ed01bb4ca..804f1bb32 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -29,12 +29,13 @@