From: vsv Date: Fri, 7 Jun 2019 08:34:03 +0000 (+0300) Subject: Provide On Plane filter and reading of validators for filters GUI definition X-Git-Tag: VEDF2019Lot4~101^2~37 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c155919c16327dae7e09cd1e6a5b6d166e844767;p=modules%2Fshaper.git Provide On Plane filter and reading of validators for filters GUI definition --- diff --git a/src/Config/Config_Common.cpp b/src/Config/Config_Common.cpp index b071546e6..33abc6a3e 100644 --- a/src/Config/Config_Common.cpp +++ b/src/Config/Config_Common.cpp @@ -86,7 +86,7 @@ bool isWidgetNode(xmlNodePtr theNode) return false; // it's parent is "feature" or "source" or a page ("box", "case") if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, WDG_GROUP, WDG_OPTIONALBOX, - WDG_TOOLBOX_BOX, WDG_RADIOBOX_ITEM, WDG_SWITCH_CASE, NULL)) + WDG_TOOLBOX_BOX, WDG_RADIOBOX_ITEM, WDG_SWITCH_CASE, WDG_FILTER, NULL)) return false; //it should not be a "source" or a "validator" node diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index ff7ee5c75..0a8f4aba4 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -63,6 +63,8 @@ const static char* WDG_RADIOBOX_ITEM = "radio"; const static char* WDG_TOOLBOX_BOX = "box"; const static char* WDG_SWITCH = "switch"; const static char* WDG_SWITCH_CASE = "case"; +const static char* WDG_FILTER = "filter"; + // Common properties (xml attributes of nodes) const static char* _ID = "id"; // NODE_WORKBENCH properties diff --git a/src/Config/Config_ValidatorReader.cpp b/src/Config/Config_ValidatorReader.cpp index e6b802a59..ffa025612 100644 --- a/src/Config/Config_ValidatorReader.cpp +++ b/src/Config/Config_ValidatorReader.cpp @@ -33,8 +33,8 @@ #include #endif -Config_ValidatorReader::Config_ValidatorReader(const std::string& theXmlFileName) -: Config_XMLReader(theXmlFileName) +Config_ValidatorReader::Config_ValidatorReader(const std::string& theXmlFileName, bool isXMLContent) +: Config_XMLReader(theXmlFileName, isXMLContent) { } @@ -85,6 +85,8 @@ void Config_ValidatorReader::processValidator(xmlNodePtr theNode) aMessage->setValidatorId(aValidatorId); aMessage->setValidatorParameters(aParameters); std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID); + if (aFeatureId.length() == 0) + aFeatureId = myExtFeatureId; aMessage->setFeatureId(aFeatureId); // parent is attribute (widget) if (!myCurrentWidget.empty()) { diff --git a/src/Config/Config_ValidatorReader.h b/src/Config/Config_ValidatorReader.h index d4cdd3940..dac03e090 100644 --- a/src/Config/Config_ValidatorReader.h +++ b/src/Config/Config_ValidatorReader.h @@ -39,9 +39,13 @@ class Config_ValidatorReader : public Config_XMLReader * Constructor * \param theXmlFile - full path to the xml file which will be processed by the reader */ - CONFIG_EXPORT Config_ValidatorReader(const std::string& theXmlFile); + CONFIG_EXPORT Config_ValidatorReader(const std::string& theXmlFile, bool isXMLContent = false); CONFIG_EXPORT virtual ~Config_ValidatorReader(); + + /// Set feature ID for cases when XML for validators is parsed from memory + CONFIG_EXPORT void setFeatureId(const std::string& theId) { myExtFeatureId = theId; } + protected: /*! * \brief Allows to customize reader's behavior for a node. Virtual. @@ -67,6 +71,7 @@ class Config_ValidatorReader : public Config_XMLReader private: std::string myCurrentWidget; + std::string myExtFeatureId; }; #endif /* CONFIG_VALIDATORREADER_H_ */ diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index 1d7de9c6b..a47496eb8 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -45,12 +45,15 @@ static const char FSEP = '/'; #endif -Config_XMLReader::Config_XMLReader(const std::string& theXmlFileName) +Config_XMLReader::Config_XMLReader(const std::string& theXmlFileName, bool isXMLContent) : myXmlDoc(NULL), myRootFileName(theXmlFileName) { - myDocumentPath = findConfigFile(theXmlFileName); - if (myDocumentPath.empty()) { - Events_InfoMessage("Config_XMLReader", "Unable to open %1").arg(theXmlFileName).send(); + isFromMemory = isXMLContent; + if (!isXMLContent) { + myDocumentPath = findConfigFile(theXmlFileName); + if (myDocumentPath.empty()) { + Events_InfoMessage("Config_XMLReader", "Unable to open %1").arg(theXmlFileName).send(); + } } } @@ -157,6 +160,13 @@ std::string Config_XMLReader::findConfigFile(const std::string theFileName, cons void Config_XMLReader::readAll() { + if (isFromMemory) { + myXmlDoc = xmlParseMemory(myRootFileName.c_str(), myRootFileName.length()); + xmlNodePtr aRoot = xmlDocGetRootElement(myXmlDoc); + readRecursively(aRoot); + return; + } + // to load external modules dependencies (like GEOM for Connector Feature) Config_ModuleReader::loadScript("salome.shaper.initConfig", false); diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h index 13b3a8b20..ad9a2d5f5 100644 --- a/src/Config/Config_XMLReader.h +++ b/src/Config/Config_XMLReader.h @@ -51,7 +51,7 @@ class Config_XMLReader * Constructor * \param theXmlFile - full path to the xml file which will be processed by the reader */ - CONFIG_EXPORT Config_XMLReader(const std::string& theXmlFile); + CONFIG_EXPORT Config_XMLReader(const std::string& theXmlFile, bool isXMLContent = false); CONFIG_EXPORT virtual ~Config_XMLReader(); /*! * Returns a path to resource files (created from ROOT_DIR environment variable) @@ -130,6 +130,8 @@ class Config_XMLReader /// A map to store all parent's attributes. /// The key has from "Node_Name:Node_Attribute" std::map myCachedAttributes; + + bool isFromMemory; }; #endif /* CONFIG_XMLREADER_H_ */ diff --git a/src/FiltersPlugin/CMakeLists.txt b/src/FiltersPlugin/CMakeLists.txt index 17303eda7..9cb138019 100644 --- a/src/FiltersPlugin/CMakeLists.txt +++ b/src/FiltersPlugin/CMakeLists.txt @@ -26,6 +26,7 @@ SET(PROJECT_HEADERS FiltersPlugin_HorizontalFace.h FiltersPlugin_VerticalFace.h FiltersPlugin_BelongsTo.h + FiltersPlugin_OnPlane.h ) SET(PROJECT_SOURCES @@ -34,6 +35,7 @@ SET(PROJECT_SOURCES FiltersPlugin_HorizontalFace.cpp FiltersPlugin_VerticalFace.cpp FiltersPlugin_BelongsTo.cpp + FiltersPlugin_OnPlane.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp b/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp index 45a045e0a..b03093e0f 100644 --- a/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp +++ b/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp @@ -46,9 +46,9 @@ bool FiltersPlugin_BelongsTo::isOk(const GeomShapePtr& theShape, static std::string XMLRepresentation = "" " " +" label=\"Objects:\"" +" tooltip=\"Select objects to limit selection.\"" +" type_choice=\"objects\">" " " ""; diff --git a/src/FiltersPlugin/FiltersPlugin_BelongsTo.h b/src/FiltersPlugin/FiltersPlugin_BelongsTo.h index f270103af..7e0b6bb6e 100644 --- a/src/FiltersPlugin/FiltersPlugin_BelongsTo.h +++ b/src/FiltersPlugin/FiltersPlugin_BelongsTo.h @@ -24,9 +24,9 @@ #include -/**\class FiltersPlugin_HorizontalFace +/**\class FiltersPlugin_BelongsTo * \ingroup DataModel -* \brief Filter for horizontal faces only +* \brief Filter for objects which are part of specified objects */ class FiltersPlugin_BelongsTo : public ModelAPI_Filter { diff --git a/src/FiltersPlugin/FiltersPlugin_OnPlane.cpp b/src/FiltersPlugin/FiltersPlugin_OnPlane.cpp new file mode 100644 index 000000000..f2771a8cf --- /dev/null +++ b/src/FiltersPlugin/FiltersPlugin_OnPlane.cpp @@ -0,0 +1,68 @@ +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "FiltersPlugin_OnPlane.h" + +#include + +bool FiltersPlugin_OnPlane::isSupported(GeomAPI_Shape::ShapeType theType) const +{ + switch (theType) { + case GeomAPI_Shape::SHELL: + case GeomAPI_Shape::FACE: + case GeomAPI_Shape::WIRE: + case GeomAPI_Shape::EDGE: + case GeomAPI_Shape::VERTEX: + return true; + } + return false; +} + +bool FiltersPlugin_OnPlane::isOk(const GeomShapePtr& theShape, + const ModelAPI_FiltersArgs& theArgs) const +{ + AttributePtr aAttr = theArgs.argument("OnPlane"); + AttributeSelectionListPtr aList = + std::dynamic_pointer_cast(aAttr); + if (!aList.get()) + return false; + // ToDo + return false; +} + +static std::string XMLRepresentation = +"" +" " +" " +" " +""; + + +std::string FiltersPlugin_OnPlane::xmlRepresentation() const +{ + return XMLRepresentation; +} + +void FiltersPlugin_OnPlane::initAttributes(ModelAPI_FiltersArgs& theArguments) +{ + theArguments.initAttribute("OnPlane", ModelAPI_AttributeSelectionList::typeId()); +} diff --git a/src/FiltersPlugin/FiltersPlugin_OnPlane.h b/src/FiltersPlugin/FiltersPlugin_OnPlane.h new file mode 100644 index 000000000..e496d9f42 --- /dev/null +++ b/src/FiltersPlugin/FiltersPlugin_OnPlane.h @@ -0,0 +1,57 @@ +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef FILTERSPLUGIN_ONPLANE_H_ +#define FILTERSPLUGIN_ONPLANE_H_ + +#include "FiltersPlugin.h" + +#include + +/**\class FiltersPlugin_OnPlane +* \ingroup DataModel +* \brief Filter for objects which belong to selected planes +*/ +class FiltersPlugin_OnPlane : public ModelAPI_Filter +{ +public: + FiltersPlugin_OnPlane() : ModelAPI_Filter() {} + + virtual const std::string& name() const { + static const std::string kName("On plane"); + return kName; + } + + /// Returns true for any type because it supports all selection types + virtual bool isSupported(GeomAPI_Shape::ShapeType theType) const override; + + /// This method should contain the filter logic. It returns true if the given shape + /// is accepted by the filter. + /// \param theShape the given shape + virtual bool isOk(const GeomShapePtr& theShape, + const ModelAPI_FiltersArgs& theArgs) const override; + + /// Returns XML string which represents GUI of the filter + virtual std::string xmlRepresentation() const override; + + /// Initializes arguments of a filter. + virtual void initAttributes(ModelAPI_FiltersArgs& theArguments) override; +}; + +#endif \ No newline at end of file diff --git a/src/FiltersPlugin/FiltersPlugin_Plugin.cpp b/src/FiltersPlugin/FiltersPlugin_Plugin.cpp index d1e5f1063..92ff9b1a1 100644 --- a/src/FiltersPlugin/FiltersPlugin_Plugin.cpp +++ b/src/FiltersPlugin/FiltersPlugin_Plugin.cpp @@ -22,6 +22,7 @@ #include "FiltersPlugin_HorizontalFace.h" #include "FiltersPlugin_VerticalFace.h" #include "FiltersPlugin_BelongsTo.h" +#include "FiltersPlugin_OnPlane.h" #include #include @@ -37,6 +38,7 @@ FiltersPlugin_Plugin::FiltersPlugin_Plugin() aFactory->registerFilter("HorizontalFaces", new FiltersPlugin_HorizontalFace); aFactory->registerFilter("VerticalFaces", new FiltersPlugin_VerticalFace); aFactory->registerFilter("BelongsTo", new FiltersPlugin_BelongsTo); + aFactory->registerFilter("OnPlane", new FiltersPlugin_OnPlane); ModelAPI_Session::get()->registerPlugin(this); } diff --git a/src/FiltersPlugin/FiltersPlugin_VerticalFace.cpp b/src/FiltersPlugin/FiltersPlugin_VerticalFace.cpp index 8af64f014..97235249f 100644 --- a/src/FiltersPlugin/FiltersPlugin_VerticalFace.cpp +++ b/src/FiltersPlugin/FiltersPlugin_VerticalFace.cpp @@ -21,6 +21,9 @@ #include #include +#include +#include +#include bool FiltersPlugin_VerticalFace::isSupported(GeomAPI_Shape::ShapeType theType) const { @@ -30,11 +33,14 @@ bool FiltersPlugin_VerticalFace::isSupported(GeomAPI_Shape::ShapeType theType) c bool FiltersPlugin_VerticalFace::isOk( const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const { - if (!theShape->isPlanar()) + if (!theShape->isFace()) return false; - GeomFacePtr aFace(new GeomAPI_Face(theShape)); + if (theShape->isPlanar()) { + GeomFacePtr aFace(new GeomAPI_Face(theShape)); - GeomPlanePtr aPlane = aFace->getPlane(); - GeomDirPtr aDir = aPlane->direction(); - return fabs(aDir->z()) <= 1.e-7; + GeomPlanePtr aPlane = aFace->getPlane(); + GeomDirPtr aDir = aPlane->direction(); + return fabs(aDir->z()) <= 1.e-7; + } + return false; } diff --git a/src/GeomValidators/GeomValidators_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp index 44d9fe27f..963f53c9a 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.cpp +++ b/src/GeomValidators/GeomValidators_ShapeType.cpp @@ -293,6 +293,9 @@ bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape, case Shell: aValid = theShape->shapeType() == GeomAPI_Shape::SHELL; break; + case Plane: + aValid = theShape->isPlanar(); + break; case Solid: aValid = theShape->isSolid() || theShape->isCompSolid() || theShape->isCompoundOfSolids(); diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp index 9f6136b7d..7eec4bec5 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -144,6 +145,10 @@ ModuleBase_FilterItem::ModuleBase_FilterItem( addItemRow(this); else { ModuleBase_WidgetFactory aFactory(aXmlString, theParent->workshop()); + Config_ValidatorReader aValidatorReader(aXmlString, true); + aValidatorReader.setFeatureId(mySelection->getKind()); + aValidatorReader.readAll(); + QVBoxLayout* aLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aLayout); @@ -208,7 +213,7 @@ void ModuleBase_FilterItem::onDelete() emit deleteItem(this); } -QList ModuleBase_FilterItem::getControls() const +QList ModuleBase_FilterItem::getControls() const { QList aWidgetsList; foreach(ModuleBase_ModelWidget* aWgt, myWidgets) { @@ -221,7 +226,6 @@ QList ModuleBase_FilterItem::getControls() const } - //***************************************************************************** //***************************************************************************** //*****************************************************************************