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
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
#include <iostream>
#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)
{
}
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()) {
* 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.
private:
std::string myCurrentWidget;
+ std::string myExtFeatureId;
};
#endif /* CONFIG_VALIDATORREADER_H_ */
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();
+ }
}
}
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);
* 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)
/// A map to store all parent's attributes.
/// The key has from "Node_Name:Node_Attribute"
std::map<std::string, std::string> myCachedAttributes;
+
+ bool isFromMemory;
};
#endif /* CONFIG_XMLREADER_H_ */
FiltersPlugin_HorizontalFace.h
FiltersPlugin_VerticalFace.h
FiltersPlugin_BelongsTo.h
+ FiltersPlugin_OnPlane.h
)
SET(PROJECT_SOURCES
FiltersPlugin_HorizontalFace.cpp
FiltersPlugin_VerticalFace.cpp
FiltersPlugin_BelongsTo.cpp
+ FiltersPlugin_OnPlane.cpp
)
SET(PROJECT_LIBRARIES
static std::string XMLRepresentation =
"<filter id = \"BelongsTo\">"
" <multi_selector id=\"BelongsTo__BelongsTo\""
-" label = \"Objects:\""
-" tooltip = \"Select objects to limit selection.\""
-" type_choice = \"objects\">"
+" label=\"Objects:\""
+" tooltip=\"Select objects to limit selection.\""
+" type_choice=\"objects\">"
" </multi_selector>"
"</filter>";
#include <ModelAPI_Filter.h>
-/**\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
{
--- /dev/null
+// 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 <ModelAPI_AttributeSelectionList.h>
+
+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<ModelAPI_AttributeSelectionList>(aAttr);
+ if (!aList.get())
+ return false;
+ // ToDo
+ return false;
+}
+
+static std::string XMLRepresentation =
+"<filter id = \"OnPlane\">"
+" <multi_selector id=\"OnPlane__OnPlane\""
+" label=\"Planes:\""
+" tooltip=\"Select planes or planar faces.\""
+" type_choice=\"faces\">"
+" <validator id=\"GeomValidators_ShapeType\" parameters=\"plane\"/>"
+" </multi_selector>"
+"</filter>";
+
+
+std::string FiltersPlugin_OnPlane::xmlRepresentation() const
+{
+ return XMLRepresentation;
+}
+
+void FiltersPlugin_OnPlane::initAttributes(ModelAPI_FiltersArgs& theArguments)
+{
+ theArguments.initAttribute("OnPlane", ModelAPI_AttributeSelectionList::typeId());
+}
--- /dev/null
+// 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 <ModelAPI_Filter.h>
+
+/**\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
#include "FiltersPlugin_HorizontalFace.h"
#include "FiltersPlugin_VerticalFace.h"
#include "FiltersPlugin_BelongsTo.h"
+#include "FiltersPlugin_OnPlane.h"
#include <ModelAPI_Session.h>
#include <ModelAPI_Filter.h>
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);
}
#include <GeomAPI_Face.h>
#include <GeomAPI_Pln.h>
+#include <GeomAPI_Solid.h>
+#include <GeomAPI_Shell.h>
+#include <GeomAPI_Cylinder.h>
bool FiltersPlugin_VerticalFace::isSupported(GeomAPI_Shape::ShapeType theType) const
{
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;
}
case Shell:
aValid = theShape->shapeType() == GeomAPI_Shape::SHELL;
break;
+ case Plane:
+ aValid = theShape->isPlanar();
+ break;
case Solid:
aValid = theShape->isSolid() || theShape->isCompSolid() ||
theShape->isCompoundOfSolids();
#include <GeomAPI_ShapeExplorer.h>
#include <Events_Loop.h>
+#include <Config_ValidatorReader.h>
#include <AIS_InteractiveContext.hxx>
#include <StdSelect_BRepOwner.hxx>
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);
emit deleteItem(this);
}
-QList<QWidget*> ModuleBase_FilterItem::getControls() const
+QList<QWidget*> ModuleBase_FilterItem::getControls() const
{
QList<QWidget*> aWidgetsList;
foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
}
-
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************