From: nds Date: Fri, 27 Mar 2015 07:38:37 +0000 (+0300) Subject: Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0 X-Git-Tag: V_1.1.0~75^2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3e3d76500389cb3a5a6eeb09f229cd3c83730dac;p=modules%2Fshaper.git Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0 Conflicts: src/SketchPlugin/SketchPlugin_Validators.cpp --- 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 4ca486e87..971e919d2 100644 Binary files a/src/PartSet/icons/tangent.png and b/src/PartSet/icons/tangent.png differ diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 68302fee1..c7ee95fcc 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -53,6 +53,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_DistanceAttrValidator); aFactory->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 @@ +