From: nds Date: Tue, 16 Dec 2014 05:50:37 +0000 (+0300) Subject: An interface creation for a separate filter in order to use as a filter the OCC reali... X-Git-Tag: before_slalome_7.5.1~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6e97b9e154406f7bff6b92404b15c7682774d152;p=modules%2Fshaper.git An interface creation for a separate filter in order to use as a filter the OCC realization of FaceFilter and EdgeFilter. --- diff --git a/src/ConstructionPlugin/plane_widget.xml b/src/ConstructionPlugin/plane_widget.xml index bf062da02..8697dcca0 100644 --- a/src/ConstructionPlugin/plane_widget.xml +++ b/src/ConstructionPlugin/plane_widget.xml @@ -5,7 +5,9 @@ label="Plane face" tooltip="Select a planar face for plane definition" shape_types="face" - use_subshapes="true" /> + use_subshapes="true"> + + +#include + /** * This object is assigned by the name * in the XML file to the specific attribute or to the whole feature. @@ -19,15 +21,31 @@ * 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& 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 diff --git a/src/ModuleBase/ModuleBase_FilterFace.cpp b/src/ModuleBase/ModuleBase_FilterFace.cpp new file mode 100644 index 000000000..8391e17be --- /dev/null +++ b/src/ModuleBase/ModuleBase_FilterFace.cpp @@ -0,0 +1,47 @@ +// 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 +#include + +#include + +#include +#include + +typedef QMap 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& 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)); +} diff --git a/src/ModuleBase/ModuleBase_FilterFace.h b/src/ModuleBase/ModuleBase_FilterFace.h new file mode 100644 index 000000000..4e6919a37 --- /dev/null +++ b/src/ModuleBase/ModuleBase_FilterFace.h @@ -0,0 +1,38 @@ +// 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 + +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& theArguments); + +protected: + /** + * It creates an OCC face filter + */ + virtual void createFilter(); + +}; + +#endif //ModuleBase_FilterFace diff --git a/src/ModuleBase/ModuleBase_FilterFactory.cpp b/src/ModuleBase/ModuleBase_FilterFactory.cpp index c1fb82fc2..f89d6e71b 100644 --- a/src/ModuleBase/ModuleBase_FilterFactory.cpp +++ b/src/ModuleBase/ModuleBase_FilterFactory.cpp @@ -16,7 +16,7 @@ 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"); @@ -48,7 +48,7 @@ void ModuleBase_FilterFactory::assignFilter(const std::string& theID, void ModuleBase_FilterFactory::filters(const std::string& theFeatureID, const std::string& theAttrID, SelectMgr_ListOfFilter& theFilters/*, - std::list& theFilters/*, + std::list& theFilters/*, std::list >& theArguments*/) const { SelectMgr_ListOfFilter aFilters; @@ -60,16 +60,17 @@ void ModuleBase_FilterFactory::filters(const std::string& theFeatureID, if (anAttr != aFeature->second.end()) { AttrFilters::const_iterator aValIter = anAttr->second.cbegin(); for (; aValIter != anAttr->second.cend(); aValIter++) { - std::map::const_iterator aFound = myIDs.find( + std::map::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); } } @@ -83,9 +84,9 @@ ModuleBase_FilterFactory::ModuleBase_FilterFactory() //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::const_iterator aIt = myIDs.find(theID); + std::map::const_iterator aIt = myIDs.find(theID); if (aIt != myIDs.end()) { return aIt->second; } diff --git a/src/ModuleBase/ModuleBase_FilterFactory.h b/src/ModuleBase/ModuleBase_FilterFactory.h index a0759f25c..043bd64ad 100644 --- a/src/ModuleBase/ModuleBase_FilterFactory.h +++ b/src/ModuleBase/ModuleBase_FilterFactory.h @@ -28,7 +28,7 @@ class ModuleBase_FilterFactory : public QObject { private: - std::map myIDs; ///< map from ID to registered filter + std::map myIDs; ///< map from ID to registered filter /// filters IDs to list of arguments typedef std::map > AttrFilters; /// filters IDs by feature ID @@ -39,7 +39,7 @@ class ModuleBase_FilterFactory : public QObject 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, @@ -53,7 +53,7 @@ class ModuleBase_FilterFactory : public QObject 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(); diff --git a/src/ModuleBase/ModuleBase_FilterLinearEdge.cpp b/src/ModuleBase/ModuleBase_FilterLinearEdge.cpp index 97f5ffa9a..a5634cba4 100644 --- a/src/ModuleBase/ModuleBase_FilterLinearEdge.cpp +++ b/src/ModuleBase/ModuleBase_FilterLinearEdge.cpp @@ -6,47 +6,43 @@ #include "ModuleBase_FilterLinearEdge.h" -#include "ModuleBase_IWorkshop.h" -#include -#include -#include +#include +#include -#include -#include +#include -#include +#include +#include -#include +typedef QMap EdgeTypes; +static EdgeTypes MyEdgeTypes; -#include -#include -#include -#include - - -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& 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 anEdge = std::shared_ptr(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)); } diff --git a/src/ModuleBase/ModuleBase_FilterLinearEdge.h b/src/ModuleBase/ModuleBase_FilterLinearEdge.h index 7f3b798f8..cdfa8e435 100644 --- a/src/ModuleBase/ModuleBase_FilterLinearEdge.h +++ b/src/ModuleBase/ModuleBase_FilterLinearEdge.h @@ -11,20 +11,27 @@ #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 + 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& theArguments); + +protected: + /** + * It creates an OCC edge filter + */ + virtual void createFilter(); }; diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 49fe8cf55..1ef62f92a 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -444,13 +444,13 @@ void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate) 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); } } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index c154d43d4..146dfa692 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -148,7 +149,8 @@ void PartSet_Module::registerFilters() XGUI_ModuleConnector* aConnector = dynamic_cast(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) diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 571c97d77..f63903b65 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -68,6 +68,7 @@ + @@ -78,11 +79,12 @@ - + +