label="Plane face"
tooltip="Select a planar face for plane definition"
shape_types="face"
- use_subshapes="true" />
+ use_subshapes="true">
+ <selection_filter id="FaceFilter" parameters="plane"/>
+ </shape_selector>
<doublevalue id="distance"
label="Distance"
tooltip="Distance from selected face to plane"
SET(PROJECT_HEADERS
ModuleBase.h
ModuleBase_Filter.h
+ ModuleBase_FilterFace.h
ModuleBase_FilterFactory.h
ModuleBase_FilterLinearEdge.h
ModuleBase_Tools.h
SET(PROJECT_SOURCES
ModuleBase_Filter.cpp
+ ModuleBase_FilterFace.cpp
ModuleBase_FilterFactory.cpp
ModuleBase_FilterLinearEdge.cpp
ModuleBase_Tools.cpp
// Created: 10 Dec 2014
// Author: Natalia ERMOLAEVA
-
#include "ModuleBase_Filter.h"
-IMPLEMENT_STANDARD_HANDLE(ModuleBase_Filter, SelectMgr_Filter);
-IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_Filter, SelectMgr_Filter);
-
-Standard_Boolean ModuleBase_Filter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+Handle(SelectMgr_Filter) ModuleBase_Filter::getFilter()
{
- return Standard_True;
+ if (myFilter.IsNull())
+ createFilter();
+
+ return myFilter;
}
#include <SelectMgr_Filter.hxx>
+#include <list>
+
/**
* This object is assigned by the name
* in the XML file to the specific attribute or to the whole feature.
* Filterss must be registered in the filters factory to be
* correctly identified by the XML string-ID.
*/
-DEFINE_STANDARD_HANDLE(ModuleBase_Filter, SelectMgr_Filter);
-class ModuleBase_Filter: public SelectMgr_Filter
+class ModuleBase_Filter
{
public:
- Standard_EXPORT ModuleBase_Filter(): SelectMgr_Filter() {}
-
- Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
-
- DEFINE_STANDARD_RTTI(ModuleBase_Filter)
+ MODULEBASE_EXPORT ModuleBase_Filter() {}
+
+ /**
+ * Returns an OCC selection filter. It can be appended into the context of a viewer
+ * It creates a filter if it has not be created yet.
+ * \return the selection filter
+ */
+ MODULEBASE_EXPORT Handle(SelectMgr_Filter) getFilter();
+
+ /**
+ * Sets the arguments to the filter.
+ * \param theArguments a list of arguments
+ */
+ MODULEBASE_EXPORT virtual void setArguments(const std::list<std::string>& theArguments) = 0;
+protected:
+ /**
+ * It creates an internal instance of the OCC filter
+ */
+ virtual void createFilter() = 0;
+
+protected:
+ Handle(SelectMgr_Filter) myFilter; // current instance of the OCC selection filter
};
#endif //ModuleBase_Filter
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_FilterFace.cpp
+// Created: 10 Dec 2014
+// Author: Natalia ERMOLAEVA
+
+
+#include "ModuleBase_FilterFace.h"
+
+#include <StdSelect_FaceFilter.hxx>
+#include <StdSelect_TypeOfFace.hxx>
+
+#include <Events_Error.h>
+
+#include <QString>
+#include <QMap>
+
+typedef QMap<QString, StdSelect_TypeOfFace> FaceTypes;
+static FaceTypes MyFaceTypes;
+
+StdSelect_TypeOfFace ModuleBase_FilterFace::faceType(const std::string& theType)
+{
+ if (MyFaceTypes.count() == 0) {
+ MyFaceTypes["plane"] = StdSelect_Plane;
+ }
+ QString aType = QString(theType.c_str()).toLower();
+ if (MyFaceTypes.contains(aType))
+ return MyFaceTypes[aType];
+ Events_Error::send("Face type defined in XML is not implemented!");
+ return StdSelect_AnyFace;
+}
+
+void ModuleBase_FilterFace::createFilter()
+{
+ myFilter = new StdSelect_FaceFilter(StdSelect_AnyFace);
+}
+
+void ModuleBase_FilterFace::setArguments(const std::list<std::string>& theArguments)
+{
+ if (theArguments.size()!= 1)
+ return;
+
+ std::string anArgument = theArguments.front();
+ Handle(StdSelect_FaceFilter) aFilter = Handle(StdSelect_FaceFilter)::DownCast(getFilter());
+ if (!aFilter.IsNull())
+ aFilter->SetType(faceType(anArgument));
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_FilterFace.h
+// Created: 10 Dec 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModuleBase_FilterFace_H
+#define ModuleBase_FilterFace_H
+
+#include "ModuleBase.h"
+
+#include "ModuleBase_Filter.h"
+
+#include <StdSelect_TypeOfFace.hxx>
+
+class ModuleBase_FilterFace: public ModuleBase_Filter
+{
+public:
+ static MODULEBASE_EXPORT StdSelect_TypeOfFace faceType(const std::string& theType);
+
+ MODULEBASE_EXPORT ModuleBase_FilterFace():
+ ModuleBase_Filter() {}
+
+ /**
+ * Sets the arguments to the filter.
+ * \param theArguments a list of arguments
+ */
+ MODULEBASE_EXPORT virtual void setArguments(const std::list<std::string>& theArguments);
+
+protected:
+ /**
+ * It creates an OCC face filter
+ */
+ virtual void createFilter();
+
+};
+
+#endif //ModuleBase_FilterFace
void ModuleBase_FilterFactory::registerFilter(const std::string& theID,
- Handle(ModuleBase_Filter) theFilter)
+ ModuleBase_Filter* theFilter)
{
if (myIDs.find(theID) != myIDs.end()) {
Events_Error::send(std::string("Filter ") + theID + " is already registered");
void ModuleBase_FilterFactory::filters(const std::string& theFeatureID,
const std::string& theAttrID,
SelectMgr_ListOfFilter& theFilters/*,
- std::list<Handle(ModuleBase_Filter)>& theFilters/*,
+ std::list<ModuleBase_Filter*>& theFilters/*,
std::list<std::list<std::string> >& theArguments*/) const
{
SelectMgr_ListOfFilter aFilters;
if (anAttr != aFeature->second.end()) {
AttrFilters::const_iterator aValIter = anAttr->second.cbegin();
for (; aValIter != anAttr->second.cend(); aValIter++) {
- std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator aFound = myIDs.find(
+ std::map<std::string, ModuleBase_Filter*>::const_iterator aFound = myIDs.find(
aValIter->first);
if (aFound == myIDs.end()) {
Events_Error::send(std::string("Filter ") + aValIter->first + " was not registered");
} else {
- Handle(ModuleBase_Filter) aFilter = aFound->second;
- if (aFilter.IsNull())
- continue;
+ ModuleBase_Filter* aFilter = aFound->second;
+ aFilter->setArguments(aValIter->second);
+ //if (aFilter.IsNull())
+ // continue;
- theFilters.Append(aFilter);//aFound->second);
+ theFilters.Append(aFilter->getFilter());//aFound->second);
//theArguments.push_back(aValIter->second);
}
}
//registerFilter(kDefaultId, new Model_FeatureFilter);
}
-const Handle(ModuleBase_Filter) ModuleBase_FilterFactory::filter(const std::string& theID) const
+const ModuleBase_Filter* ModuleBase_FilterFactory::filter(const std::string& theID) const
{
- std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator aIt = myIDs.find(theID);
+ std::map<std::string, ModuleBase_Filter*>::const_iterator aIt = myIDs.find(theID);
if (aIt != myIDs.end()) {
return aIt->second;
}
class ModuleBase_FilterFactory : public QObject
{
private:
- std::map<std::string, Handle_ModuleBase_Filter> myIDs; ///< map from ID to registered filter
+ std::map<std::string, ModuleBase_Filter*> myIDs; ///< map from ID to registered filter
/// filters IDs to list of arguments
typedef std::map<std::string, std::list<std::string> > AttrFilters;
/// filters IDs by feature ID
public:
/// Registers the instance of the filter by the ID
MODULEBASE_EXPORT virtual void registerFilter(const std::string& theID,
- Handle_ModuleBase_Filter theFilter);
+ ModuleBase_Filter* theFilter);
/// Assigns filter to the attribute of the feature
MODULEBASE_EXPORT virtual void assignFilter(const std::string& theID,
SelectMgr_ListOfFilter& theFilters) const;
/// Returns registered filter by its Id
- MODULEBASE_EXPORT virtual const Handle_ModuleBase_Filter filter(const std::string& theID) const;
+ MODULEBASE_EXPORT virtual const ModuleBase_Filter* filter(const std::string& theID) const;
protected:
ModuleBase_FilterFactory();
#include "ModuleBase_FilterLinearEdge.h"
-#include "ModuleBase_IWorkshop.h"
-#include <ModelAPI_Session.h>
-#include <ModelAPI_Document.h>
-#include <ModelAPI_ResultConstruction.h>
+#include <StdSelect_EdgeFilter.hxx>
+#include <StdSelect_TypeOfEdge.hxx>
-#include <AIS_InteractiveObject.hxx>
-#include <AIS_Shape.hxx>
+#include <Events_Error.h>
-#include <StdSelect_BRepOwner.hxx>
+#include <QString>
+#include <QMap>
-#include <GeomAPI_Edge.h>
+typedef QMap<QString, StdSelect_TypeOfEdge> EdgeTypes;
+static EdgeTypes MyEdgeTypes;
-#include <BRep_Tool.hxx>
-#include <TopoDS.hxx>
-#include <TopoDS_Edge.hxx>
-#include <Geom_Curve.hxx>
-
-
-IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterLinearEdge, ModuleBase_Filter);
-IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_FilterLinearEdge, ModuleBase_Filter);
+StdSelect_TypeOfEdge ModuleBase_FilterLinearEdge::edgeType(const std::string& theType)
+{
+ if (MyEdgeTypes.count() == 0) {
+ MyEdgeTypes["line"] = StdSelect_Line;
+ MyEdgeTypes["circle"] = StdSelect_Circle;
+ }
+ QString aType = QString(theType.c_str()).toLower();
+ if (MyEdgeTypes.contains(aType))
+ return MyEdgeTypes[aType];
+ Events_Error::send("Edge type defined in XML is not implemented!");
+ return StdSelect_AnyEdge;
+}
+void ModuleBase_FilterLinearEdge::createFilter()
+{
+ myFilter = new StdSelect_EdgeFilter(StdSelect_AnyEdge);
+}
-Standard_Boolean ModuleBase_FilterLinearEdge::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+void ModuleBase_FilterLinearEdge::setArguments(const std::list<std::string>& theArguments)
{
- Standard_Boolean isOk = ModuleBase_Filter::IsOk(theOwner);
- if (isOk && theOwner->HasSelectable()) {
- Handle(AIS_InteractiveObject) anAIS =
- Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
- if (!anAIS.IsNull()) {
- Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
- if (aShapeAIS) {
- const TopoDS_Shape& aShape = aShapeAIS->Shape();
- if (aShape.ShapeType() == TopAbs_EDGE) {
- std::shared_ptr<GeomAPI_Edge> anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge());
- anEdge->setImpl(new TopoDS_Shape(aShape));
-
- isOk = anEdge->isLine();
- }
- }
- }
- }
- return isOk;
+ if (theArguments.size()!= 1)
+ return;
+
+ std::string anArgument = theArguments.front();
+ Handle(StdSelect_EdgeFilter) aFilter = Handle(StdSelect_EdgeFilter)::DownCast(getFilter());
+ if (!aFilter.IsNull())
+ aFilter->SetType(edgeType(anArgument));
}
#include "ModuleBase_Filter.h"
-/**
-* A filter which provides filtering of selection in 3d viewer.
-* Installing of this filter lets to select only object of requested type
-*/
-DEFINE_STANDARD_HANDLE(ModuleBase_FilterLinearEdge, ModuleBase_Filter);
+#include <StdSelect_TypeOfEdge.hxx>
+
class ModuleBase_FilterLinearEdge: public ModuleBase_Filter
{
public:
- Standard_EXPORT ModuleBase_FilterLinearEdge():
- ModuleBase_Filter() {}
+ static MODULEBASE_EXPORT StdSelect_TypeOfEdge edgeType(const std::string& theType);
- Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+ MODULEBASE_EXPORT ModuleBase_FilterLinearEdge():
+ ModuleBase_Filter() {}
- DEFINE_STANDARD_RTTI(ModuleBase_FilterLinearEdge)
+ /**
+ * Sets the arguments to the filter.
+ * \param theArguments a list of arguments
+ */
+ MODULEBASE_EXPORT virtual void setArguments(const std::list<std::string>& theArguments);
+
+protected:
+ /**
+ * It creates an OCC edge filter
+ */
+ virtual void createFilter();
};
if (aSelFilter.IsNull())
continue;
- Handle(ModuleBase_Filter) aFilter = Handle(ModuleBase_Filter)::DownCast(aIt.Value());
- if (aFilter.IsNull())
- continue;
+ //Handle(ModuleBase_Filter) aFilter = Handle(ModuleBase_Filter)::DownCast(aIt.Value());
+ //if (aFilter.IsNull())
+ // continue;
if (myIsActive)
- aViewer->addSelectionFilter(aFilter);
+ aViewer->addSelectionFilter(aSelFilter);
else
- aViewer->removeSelectionFilter(aFilter);
+ aViewer->removeSelectionFilter(aSelFilter);
}
}
#include <ModuleBase_WidgetEditor.h>
#include <ModuleBase_FilterFactory.h>
#include <ModuleBase_FilterLinearEdge.h>
+#include <ModuleBase_FilterFace.h>
#include <ModelAPI_Object.h>
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
- aFactory->registerFilter("LinearEdgeFilter", new ModuleBase_FilterLinearEdge);
+ aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
+ aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
}
void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
<shape_selector id="ConstraintEntityA" label="Circle or Arc" tooltip="Select a circle or an arc in the viewer"
shape_types="edge">
<validator id="SketchPlugin_ResultArc"/>
+ <selection_filter id="EdgeFilter" parameters="circle"/>
</shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
<doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
<sketch_constraint_shape_selector id="ConstraintEntityA"
label="First line" tooltip="Select an line in the viewer"
shape_types="edge" use_subshapes="true">
- <selection_filter id="LinearEdgeFilter"/>
+ <selection_filter id="EdgeFilter" parameters="line"/>
</sketch_constraint_shape_selector>
<sketch_constraint_shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer"
shape_types="edge" use_subshapes="true">
+ <selection_filter id="EdgeFilter" parameters="line"/>
<validator id="SketchPlugin_DifferentObjects"/>
</sketch_constraint_shape_selector>