From 3e3d76500389cb3a5a6eeb09f229cd3c83730dac Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 27 Mar 2015 10:38:37 +0300 Subject: [PATCH] Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0 Conflicts: src/SketchPlugin/SketchPlugin_Validators.cpp --- src/Config/Config_Common.cpp | 2 +- src/Config/Config_Common.h | 2 ++ src/Config/Config_Keywords.h | 1 + src/Config/Config_ValidatorReader.cpp | 42 +++++++++++++++-------- src/Config/Config_ValidatorReader.h | 8 +++++ src/PartSet/PartSet_Module.cpp | 3 ++ src/PartSet/PartSet_Validators.cpp | 30 ++++++++++++++++ src/PartSet/PartSet_Validators.h | 17 +++++++++ src/PartSet/icons/tangent.png | Bin 433 -> 365 bytes src/SketchPlugin/SketchPlugin_Plugin.cpp | 2 ++ src/SketchPlugin/plugin-Sketch.xml | 3 ++ 11 files changed, 94 insertions(+), 16 deletions(-) diff --git a/src/Config/Config_Common.cpp b/src/Config/Config_Common.cpp index 8ffc9e126..8c8cde427 100644 --- a/src/Config/Config_Common.cpp +++ b/src/Config/Config_Common.cpp @@ -69,7 +69,7 @@ bool isWidgetNode(xmlNodePtr theNode) { if(!isElementNode(theNode)) return false; - // it's parent is "feature" or "source" + // it's parent is "feature" or "source" or a page ("box", "case") if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, WDG_TOOLBOX_BOX, WDG_SWITCH_CASE, NULL)) return false; diff --git a/src/Config/Config_Common.h b/src/Config/Config_Common.h index 52fc1e172..1850f8a7b 100644 --- a/src/Config/Config_Common.h +++ b/src/Config/Config_Common.h @@ -43,6 +43,8 @@ CONFIG_EXPORT bool isElementNode(xmlNodePtr theNode); */ CONFIG_EXPORT bool isNode(xmlNodePtr theNode, const char* theNodeName, ...); +//#define isNode(p) _isNode(p, NULL) + /*! * Checks if the given node is attribute node. * Attribute node represents a widget, that is able to store/restore diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index afb80188b..bc115a764 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -19,6 +19,7 @@ const static char* NODE_FEATURE = "feature"; const static char* NODE_SOURCE = "source"; const static char* NODE_VALIDATOR = "validator"; const static char* NODE_SELFILTER = "selection_filter"; +const static char* NODE_XMLPARENT = "libxml_parent"; // Widgets const static char* WDG_INFO = "label"; diff --git a/src/Config/Config_ValidatorReader.cpp b/src/Config/Config_ValidatorReader.cpp index d03dff58d..ef969cd55 100644 --- a/src/Config/Config_ValidatorReader.cpp +++ b/src/Config/Config_ValidatorReader.cpp @@ -42,11 +42,26 @@ void Config_ValidatorReader::processNode(xmlNodePtr theNode) processSelectionFilter(theNode); } else if (isNode(theNode, NODE_FEATURE, NULL)) { storeAttribute(theNode, _ID); + } else if (isWidgetNode(theNode)) { + storeAttribute(theNode, _ID); + // Store widget name to restore it's id on validator/selector processing + myCurrentWidget = getNodeName(theNode); } //Process SOURCE nodes. Config_XMLReader::processNode(theNode); } +void Config_ValidatorReader::cleanup(xmlNodePtr theNode) +{ + if (isNode(theNode, NODE_FEATURE, NULL)) { + cleanupAttribute(theNode, _ID); + } else if (isWidgetNode(theNode)) { + cleanupAttribute(NODE_XMLPARENT, _ID); + // Cleanup widget name when leave the widget node. + myCurrentWidget = ""; + } +} + bool Config_ValidatorReader::processChildren(xmlNodePtr aNode) { return true; @@ -63,14 +78,12 @@ void Config_ValidatorReader::processValidator(xmlNodePtr theNode) getParametersInfo(theNode, aValidatorId, aParameters); aMessage->setValidatorId(aValidatorId); aMessage->setValidatorParameters(aParameters); - //TODO(sbh): update feature/attribute id restoring - // when "cleanup" technique will be available (v. >= 1.1.0) - xmlNodePtr aFeatureOrWdgNode = theNode->parent; - if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) { - aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID)); - } else { - aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID)); - aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID)); + std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID); + aMessage->setFeatureId(aFeatureId); + // parent is attribute (widget) + if (!myCurrentWidget.empty()) { + std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID); + aMessage->setAttributeId(aParentId); } aEvLoop->send(aMessage); } @@ -86,13 +99,12 @@ void Config_ValidatorReader::processSelectionFilter(xmlNodePtr theNode) getParametersInfo(theNode, aSelectionFilterId, aParameters); aMessage->setSelectionFilterId(aSelectionFilterId); aMessage->setFilterParameters(aParameters); - - xmlNodePtr aFeatureOrWdgNode = theNode->parent; - if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) { - aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID)); - } else { - aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID)); - aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID)); + std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID); + aMessage->setFeatureId(aFeatureId); + // parent is attribute (widget) + if (!myCurrentWidget.empty()) { + std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID); + aMessage->setAttributeId(aParentId); } aEvLoop->send(aMessage); } diff --git a/src/Config/Config_ValidatorReader.h b/src/Config/Config_ValidatorReader.h index f2ac6293d..59f6acffb 100644 --- a/src/Config/Config_ValidatorReader.h +++ b/src/Config/Config_ValidatorReader.h @@ -45,6 +45,11 @@ class Config_ValidatorReader : public Config_XMLReader */ virtual bool processChildren(xmlNodePtr aNode); + /*! + * Cleans the cached information about parent feature or attribute (widget) + */ + virtual void cleanup(xmlNodePtr theNode); + /*! * \brief Retrieves all the necessary info from the validator node. * Sends ValidatorLoaded event @@ -55,6 +60,9 @@ class Config_ValidatorReader : public Config_XMLReader * Sends SelectionFilterLoaded event */ void processSelectionFilter(xmlNodePtr theNode); + + private: + std::string myCurrentWidget; }; #endif /* CONFIG_VALIDATORREADER_H_ */ diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index ad9296bc8..20cd41101 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -142,6 +142,9 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("PartSet_SketchEntityValidator", new PartSet_SketchEntityValidator); + + aFactory->registerValidator("PartSet_SameTypeAttr", + new PartSet_SameTypeAttrValidator); } void PartSet_Module::registerFilters() diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index be4ffafa8..6d17784f7 100644 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -266,3 +267,32 @@ bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute, return isSketchEntities; } + + + +bool PartSet_SameTypeAttrValidator::isValid( + const AttributePtr& theAttribute, const std::list& theArguments ) const +{ + // there is a check whether the feature contains a point and a linear edge or two point values + std::string aParamA = theArguments.front(); + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); + if (!aRefAttr) + return false; + + bool isObject = aRefAttr->isObject(); + ObjectPtr anObject = aRefAttr->object(); + if (isObject && anObject) { + FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject); + + AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA); + ObjectPtr aOtherObject = aOtherAttr->object(); + FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject); + return aRefFea->getKind() == aOtherFea->getKind(); + } + return false; +} + diff --git a/src/PartSet/PartSet_Validators.h b/src/PartSet/PartSet_Validators.h index eb9f8a06b..7a7f2333c 100644 --- a/src/PartSet/PartSet_Validators.h +++ b/src/PartSet/PartSet_Validators.h @@ -99,4 +99,21 @@ class PartSet_SketchEntityValidator : public ModelAPI_AttributeValidator const std::list& theArguments) const; }; +/**\class PartSet_SameTypeAttrValidator + * \ingroup Validators + * \brief Validator for the tangent constraint input. + * + * It just checks that distance is greater than zero. + */ +class PartSet_SameTypeAttrValidator : public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; +}; + + #endif diff --git a/src/PartSet/icons/tangent.png b/src/PartSet/icons/tangent.png index 4ca486e87c9a76f65b3061579dbc94a98ff77567..971e919d20d89067acd7429afb31d97cd48be709 100644 GIT binary patch delta 280 zcmV+z0q6d)1MLEkJPN@801m+cxRGn^kwzwe0P9IaK~y+Tg^?i=!Y~j;J5W(kiNIkx zIR&BzK=crZasvc{84kcvI06E}5fF$91QJhy=C%=;iDC z=rmk&q$mYzZ~!-f_uNZ|%sHq4^-v9&jqn5(U?TAT2zt%4XE`?JJ&5gd(Zpca6mCF& zU5-8+AR#}qt7Ck(XP_2yX8No%wDfk-H1rEMqq}F`30j4sxtJedYM=GdF3ig++S>gP z|Ba$T%y*F3q7Zt~UviOv(iMf!i=w5Nub}hiA=sP%9-9LSpC|+eY{Y!_35MVR{xS~8 eeS$C)eF34;ob;>S9Z3KH002ovPDHK)LSTYj<9s#% delta 348 zcmV-i0i*uy0;~~_tNZ`%ot~b` z%>JdS?LxeZA92~y%S1#4OD{CB7qgD1Or&IO199(#@E}IL-cF*nv3T~vqqr+Qk#^vJ z^V+(i_#ocImmuc*C>E`nP@LwaIHUL+Pa=)fH}9txe~Vi&^&d<registerValidator("SketchPlugin_ExternalValidator", new SketchPlugin_ExternalValidator); + aFactory->registerValidator("SketchPlugin_TangentAttr", + new SketchPlugin_TangentAttrValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 67ae5e124..c6c0ef201 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -179,6 +179,8 @@ + + @@ -190,6 +192,7 @@ + -- 2.39.2