Moving the algorithm of a point get from a Vertex shape into a tool method to be called where it is necessary.
#include "ModuleBase_ViewerPrs.h"
#include "ModuleBase_IPropertyPanel.h"
#include "ModuleBase_ISelection.h"
+#include "ModuleBase_IViewer.h"
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Document.h>
ModuleBase_Operation::~ModuleBase_Operation()
{
delete myDescription;
+ clearPreselection();
}
QString ModuleBase_Operation::id() const
return false;
ModuleBase_ModelWidget* aWgt, *aFilledWgt = 0;
- ModuleBase_ViewerPrs aPrs;
QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
- QList<ModuleBase_ViewerPrs>::const_iterator aPIt;
+ QList<ModuleBase_WidgetValueFeature*>::const_iterator aPIt;
bool isSet = false;
for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin();
(aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd());
++aWIt, ++aPIt) {
aWgt = (*aWIt);
- aPrs = (*aPIt);
- ModuleBase_WidgetValueFeature aValue;
- aValue.setObject(aPrs.object());
- // Check if the selection has a selected point
- // for today it is impossible to do because
- // the selected point demands convertation to Sketch plane 2d
- if (!aWgt->setValue(&aValue)) {
+ ModuleBase_WidgetValueFeature* aValue = (*aPIt);
+ if (!aWgt->setValue(aValue)) {
isSet = false;
break;
} else {
}
void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection,
- ModuleBase_IViewer* /*theViewer*/)
+ ModuleBase_IViewer* theViewer)
{
- myPreSelection.clear();
+ clearPreselection();
+ QList<ModuleBase_ViewerPrs> aPreSelected;
// Check that the selected result are not results of operation feature
- QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
FeaturePtr aFeature = feature();
if (aFeature) {
+ QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+
std::list<ResultPtr> aResults = aFeature->results();
QList<ObjectPtr> aResList;
std::list<ResultPtr>::const_iterator aIt;
foreach (ModuleBase_ViewerPrs aPrs, aSelected) {
if ((!aResList.contains(aPrs.object())) && (aPrs.object() != aFeature))
- myPreSelection.append(aPrs);
+ aPreSelected.append(aPrs);
}
} else
- myPreSelection = aSelected;
+ aPreSelected = theSelection->getSelected();
+
+ // convert the selection values to the values, which are set to the operation widgets
+
+ Handle(V3d_View) aView = theViewer->activeView();
+ foreach (ModuleBase_ViewerPrs aPrs, aPreSelected) {
+ ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
+ aValue->setObject(aPrs.object());
+
+ double aX, anY;
+ if (getViewerPoint(aPrs, theViewer, aX, anY))
+ aValue->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
+ myPreSelection.append(aValue);
+ }
}
void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
return isApplyed;
}
+bool ModuleBase_Operation::getViewerPoint(ModuleBase_ViewerPrs thePrs,
+ ModuleBase_IViewer* theViewer,
+ double& theX, double& theY)
+{
+ return false;
+}
+
+void ModuleBase_Operation::clearPreselection()
+{
+ while (!myPreSelection.isEmpty()) {
+ delete myPreSelection.takeFirst();
+ }
+}
void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp)
{
class ModuleBase_IPropertyPanel;
class ModuleBase_ISelection;
class ModuleBase_IViewer;
+class ModuleBase_WidgetValueFeature;
class QKeyEvent;
/// \return true if the point is set
virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
+ /// Return a widget value point by the selection and the viewer position
+ /// The default realization returns false
+ /// \param thePrs the presentation
+ /// \param theViewer a viewer to have the viewer the eye position
+ /// \param theX the horizontal coordinate
+ /// \param theY the vertical coordinate
+ /// \return true if the point exits in the selection
+ virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs,
+ ModuleBase_IViewer* theViewer,
+ double& theX, double& theY);
+
+ // Removes the preselection information and clears the map of preselection
+ void clearPreselection();
+
protected:
FeaturePtr myFeature; /// the operation feature to be handled
QStringList myNestedFeatures;
/// List of pre-selected object
- QList<ModuleBase_ViewerPrs> myPreSelection;
+ QList<ModuleBase_WidgetValueFeature*> myPreSelection;
/// Access to property panel
ModuleBase_IPropertyPanel* myPropertyPanel;
PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
} else {
ModuleBase_ViewerPrs aPrs = aSelected.first();
+ if (getViewerPoint(aPrs, theViewer, aX, anY)) {
+ ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+ PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
+ }
const TopoDS_Shape& aShape = aPrs.shape();
- if (!aShape.IsNull()) {
- if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
- const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
- if (!aVertex.IsNull()) {
- aPoint = BRep_Tool::Pnt(aVertex);
- PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
- ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
- PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
- }
- } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
- PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
- }
+ if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
+ PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
}
}
ObjectPtr aFeature;
commit();
}
+bool PartSet_OperationFeatureBase::getViewerPoint(ModuleBase_ViewerPrs thePrs,
+ ModuleBase_IViewer* theViewer,
+ double& theX, double& theY)
+{
+ return PartSet_Tools::hasVertexShape(thePrs, sketch(), theViewer->activeView(),
+ theX, theY);
+}
+
/*bool PartSet_OperationFeatureBase::setWidgetValue(ObjectPtr theFeature, double theX, double theY)
{
ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
ModuleBase_ISelection* theSelection);
+ protected:
+ /// Return a widget value point by the selection and the viewer position
+ /// \param thePrs the presentation
+ /// \param theViewer a viewer to have the viewer the eye position
+ /// \param theX the horizontal coordinate
+ /// \param theY the vertical coordinate
+ /// \return true if the point exits in the selection
+ virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs,
+ ModuleBase_IViewer* theViewer,
+ double& theX, double& theY);
protected:
CompositeFeaturePtr mySketch; ///< the sketch of the feature
#include <XGUI_Constants.h>
#include <V3d_View.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS.hxx>
-#include <BRep_Tool.hxx>
-#include <TopoDS.hxx>
#ifdef _DEBUG
#include <QDebug>
PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
} else {
ModuleBase_ViewerPrs aPrs = aSelected.first();
+ if (getViewerPoint(aPrs, theViewer, aX, anY)) {
+ ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+ PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
+ isClosedContour = true;
+ }
const TopoDS_Shape& aShape = aPrs.shape();
- if (!aShape.IsNull()) {
- if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
- const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
- if (!aVertex.IsNull()) {
- aPoint = BRep_Tool::Pnt(aVertex);
- PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
- ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
- PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
- isClosedContour = true;
- }
- } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
- ObjectPtr aObject = aPrs.object();
- if (sketch()->isSub(aObject))
- PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
- else {
- // we have to create the selected edge for the current sketch
- ResultPtr aRes = PartSet_Tools::createFixedObjectByEdge(aPrs, sketch());
- aSelected.first().setFeature(aRes);
- }
+ if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
+ ObjectPtr aObject = aPrs.object();
+ if (sketch()->isSub(aObject))
+ PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
+ else {
+ // we have to create the selected edge for the current sketch
+ ResultPtr aRes = PartSet_Tools::createFixedObjectByEdge(aPrs, sketch());
+ aSelected.first().setFeature(aRes);
}
}
}
#include <SketchPlugin_Line.h>
#include <V3d_View.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS.hxx>
-#include <BRep_Tool.hxx>
#include <AIS_DimensionOwner.hxx>
#include <AIS_DimensionSelectionMode.hxx>
// 1. find all features with skipping features with selected vertex shapes
theFeature2Attribute.clear();
// firstly, collect the features without local selection
+ double aX, anY;
foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
- const TopoDS_Shape& aShape = aPrs.shape();
- if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
- const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
- if (!aVertex.IsNull()) {
- continue;
- }
- }
+ if (getViewerPoint(aPrs, theViewer, aX, anY))
+ continue;
else {
ObjectPtr aObject = aPrs.object();
if (!aObject)
// if the list already has this feature, the local selection is skipped
// that means that if the selection contains a feature and a feature with local selected point,
// the edit is performed for a full feature
- Handle(V3d_View) aView = theViewer->activeView();
foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
- const TopoDS_Shape& aShape = aPrs.shape();
- if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
- const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
- if (aVertex.IsNull())
- continue;
+ if (getViewerPoint(aPrs, theViewer, aX, anY)) {
ObjectPtr aObject = aPrs.object();
if (!aObject)
continue;
continue;
// append the attribute of the vertex if it is found on the current feature
- gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
- double aVX, aVY;
- PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aVX, aVY);
boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D = PartSet_Tools::getFeaturePoint(
- aFeature, aVX, aVY);
+ aFeature, aX, anY);
std::string anAttribute = aFeature->data()->id(aPoint2D);
std::list<std::string> aList;
if (theFeature2Attribute.find(aFeature) != theFeature2Attribute.end())
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
+#include <TopoDS_Vertex.hxx>
#ifdef _DEBUG
#include <QDebug>
}
}
return ResultPtr();
-}
\ No newline at end of file
+}
+
+bool PartSet_Tools::hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
+ Handle_V3d_View theView, double& theX, double& theY)
+{
+ bool aHasVertex = false;
+
+ const TopoDS_Shape& aShape = thePrs.shape();
+ if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX)
+ {
+ const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
+ if (!aVertex.IsNull())
+ {
+ gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+ PartSet_Tools::convertTo2D(aPoint, theSketch, theView, theX, theY);
+ aHasVertex = true;
+ }
+ }
+
+ return aHasVertex;
+}
/// \param theEdge - the edge
/// \return result object with external edge if it is found
static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, boost::shared_ptr<GeomAPI_Edge> theEdge);
+
+ /// Returns whether the selected presentation has a shape with the vertex type
+ /// \param thePrs a selected presentation
+ /// \param theSketch the sketch feature
+ /// \param theView a 3D view
+ /// \param theX the output horizontal coordinate of the point
+ /// \param theY the output vertical coordinate of the point
+ static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
+ Handle_V3d_View theView, double& theX, double& theY);
};
#endif