#include "PartSet_MenuMgr.h"
#include "PartSet_Module.h"
#include "PartSet_SketcherMgr.h"
+#include "PartSet_Tools.h"
#include <GeomAPI_Pnt2d.h>
#include <GeomDataAPI_Point2D.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Sketch.h>
#include <ModuleBase_ISelection.h>
#include <ModuleBase_Operation.h>
#include <QAction>
#include <QMenu>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+
PartSet_MenuMgr::PartSet_MenuMgr(PartSet_Module* theModule)
: QObject(theModule), myModule(theModule), myPrevId(-1)
{
if (!theList.contains(aObj)) {
std::shared_ptr<GeomAPI_Pnt2d> aOrig = getPoint(theStartCoin, theAttr);
theList.append(aObj);
- const std::set<AttributePtr> aRefsList = aObj->data()->refsToMe();
+ const std::set<AttributePtr>& aRefsList = aObj->data()->refsToMe();
std::set<AttributePtr>::const_iterator aIt;
for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
myCoinsideLines.clear();
ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
- QObjectPtrList aObjects = aSelection->selectedPresentations();
- if (aObjects.size() > 0) {
+
+ NCollection_List<TopoDS_Shape> aShapeList;
+ std::list<ObjectPtr> aObjectsList;
+ aSelection->selectedShapes(aShapeList, aObjectsList);
+ bool aIsDetach = false;
+
+ if (aShapeList.Extent() == 1) {
+ TopoDS_Shape aShape = aShapeList.First();
+ if (aShape.ShapeType() == TopAbs_VERTEX) {
+ // Find 2d coordinates
+ FeaturePtr aSketchFea = myModule->sketchMgr()->activeSketch();
+ std::shared_ptr<SketchPlugin_Sketch> aSketch =
+ std::dynamic_pointer_cast<SketchPlugin_Sketch>(aSketchFea);
+ gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
+ std::shared_ptr<GeomAPI_Pnt> aPnt3d(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+ std::shared_ptr<GeomAPI_Pnt2d> aSelPnt = aSketch->to2D(aPnt3d);
+
+ // Find coincident in these coordinates
+ ObjectPtr aObj = aObjectsList.front();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
+ const std::set<AttributePtr>& aRefsList = aFeature->data()->refsToMe();
+ std::set<AttributePtr>::const_iterator aIt;
+ FeaturePtr aCoincident;
+ for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
+ std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
+ FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+ if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
+ std::shared_ptr<GeomAPI_Pnt2d> a2dPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ if (aSelPnt->isEqual(a2dPnt)) {
+ aCoincident = aConstrFeature;
+ break;
+ }
+ }
+ }
+ // If we have coincidence then add Detach menu
+ if (aCoincident.get() != NULL) {
+ mySelectedFeature = aCoincident;
+ findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ if (myCoinsideLines.size() > 0) {
+ aIsDetach = true;
+ QMenu* aSubMenu = theMenu->addMenu(tr("Detach"));
+ QAction* aAction;
+ int i = 0;
+ foreach (FeaturePtr aCoins, myCoinsideLines) {
+ aAction = aSubMenu->addAction(aCoins->data()->name().c_str());
+ aAction->setData(QVariant(i));
+ i++;
+ }
+ connect(aSubMenu, SIGNAL(hovered(QAction*)), SLOT(onLineHighlighted(QAction*)));
+ connect(aSubMenu, SIGNAL(aboutToHide()), SLOT(onDetachMenuHide()));
+ connect(aSubMenu, SIGNAL(triggered(QAction*)), SLOT(onLineDetach(QAction*)));
+ }
+ }
+ }
+ }
+ if ((!aIsDetach) && (aObjectsList.size() > 0)) {
bool hasFeature = false;
FeaturePtr aFeature;
- foreach(ObjectPtr aObject, aObjects) {
+ std::list<ObjectPtr>::const_iterator aIt;
+ ObjectPtr aObject;
+ for (aIt = aObjectsList.cbegin(); aIt != aObjectsList.cend(); ++aIt) {
+ aObject = (*aIt);
aFeature = ModelAPI_Feature::feature(aObject);
if (aFeature.get() != NULL) {
hasFeature = true;
}
}
- if (hasFeature) {
- bool aIsDetach = false;
- if (aObjects.size() == 1) {
- if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
- /// If the feature is coincident then we use Detach command instead Delete
- mySelectedFeature = aFeature;
- findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_A());
- findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_B());
- if (myCoinsideLines.size() > 0) {
- aIsDetach = true;
- QMenu* aSubMenu = theMenu->addMenu(tr("Detach"));
- QAction* aAction;
- int i = 0;
- foreach (FeaturePtr aCoins, myCoinsideLines) {
- aAction = aSubMenu->addAction(aCoins->data()->name().c_str());
- aAction->setData(QVariant(i));
- i++;
- }
- connect(aSubMenu, SIGNAL(hovered(QAction*)), SLOT(onLineHighlighted(QAction*)));
- connect(aSubMenu, SIGNAL(aboutToHide()), SLOT(onDetachMenuHide()));
- connect(aSubMenu, SIGNAL(triggered(QAction*)), SLOT(onLineDetach(QAction*)));
- }
- }
- }
- if (!aIsDetach)
+ if (hasFeature)
theMenu->addAction(theStdActions["DELETE_CMD"]);
- }
}
bool isAuxiliary;
if (canSetAuxiliary(isAuxiliary)) {
#include <GeomAPI_AISObject.h>
#include <GeomAPI_Dir.h>
#include <GeomAPI_PlanarEdges.h>
-#include <GeomAPI_XYZ.h>
-#include <GeomDataAPI_Dir.h>
-#include <GeomDataAPI_Point.h>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <ModelAPI_AttributeRefList.h>
return false;
}
-std::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
-{
- std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
-
- std::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
- ->added(aY->xyz()->multiplied(theY));
-
- return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
-}
-
-std::shared_ptr<GeomAPI_Pnt2d> SketchPlugin_Sketch::to2D(
- const std::shared_ptr<GeomAPI_Pnt>& thePnt)
-{
- std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
- return thePnt->to2D(aC->pnt(), aX->dir(), aY);
-}
-
-
-bool SketchPlugin_Sketch::isPlaneSet()
-{
- std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-
- return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
-}
-
-std::shared_ptr<GeomAPI_Pln> SketchPlugin_Sketch::plane()
-{
- std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-
- if (!anOrigin || !aNorm)
- return std::shared_ptr<GeomAPI_Pln>();
-
- return std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
-}
-
-std::shared_ptr<GeomAPI_Ax3> SketchPlugin_Sketch::coordinatePlane() const
-{
- DataPtr aData = data();
- std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::NORM_ID()));
-
- return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aNorm->dir()));
-}
void SketchPlugin_Sketch::erase()
{
#include <GeomAPI_Pln.h>
#include <GeomAPI_IPresentable.h>
#include <GeomAPI_Ax3.h>
+#include <GeomAPI_XYZ.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
#include <list>
#define YZ_PLANE_COLOR "#ff0000"
}
/// Converts a 2D sketch space point into point in 3D space
- SKETCHPLUGIN_EXPORT std::shared_ptr<GeomAPI_Pnt> to3D(const double theX, const double theY);
+ /// \param theX an X coordinate
+ /// \param theY an Y coordinate
+ std::shared_ptr<GeomAPI_Pnt> to3D(const double theX, const double theY) const
+ {
+ std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ data()->attribute(ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(NORM_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(DIRX_ID()));
+ std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+
+ std::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
+ ->added(aY->xyz()->multiplied(theY));
+
+ return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
+ }
+
+ /// Returns the point projected into the sketch plane
+ /// \param thePnt a source 3d point
+ std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePnt) const
+ {
+ std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ data()->attribute(ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(NORM_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(DIRX_ID()));
+ std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+ return thePnt->to2D(aC->pnt(), aX->dir(), aY);
+ }
/// Returns true if this feature must be displayed in the history (top level of Part tree)
SKETCHPLUGIN_EXPORT virtual bool isInHistory()
SketchPlugin_Sketch();
/// Returns the basis plane for the sketch
- std::shared_ptr<GeomAPI_Pln> plane();
+ std::shared_ptr<GeomAPI_Pln> plane() const
+ {
+ std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ data()->attribute(ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(NORM_ID()));
- SKETCHPLUGIN_EXPORT std::shared_ptr<GeomAPI_Ax3> coordinatePlane() const;
+ if (!anOrigin || !aNorm)
+ return std::shared_ptr<GeomAPI_Pln>();
+
+ return std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
+ }
+
+ /// Returns currently defined plane as an object of Ax3
+ std::shared_ptr<GeomAPI_Ax3> coordinatePlane() const
+ {
+ DataPtr aData = data();
+ std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aData->attribute(ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(DIRX_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(NORM_ID()));
+
+ return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aNorm->dir()));
+ }
+
+ /// Checks whether the plane is set in the sketch.
+ /// \returns the boolean state
+ bool isPlaneSet() const
+ {
+ std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(NORM_ID()));
+
+ return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
+ }
- //virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
/// removes also all sub-sketch elements
SKETCHPLUGIN_EXPORT virtual void erase();
/// Construction result is allways recomuted on the fly
SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
- /// Returns the point projected into the sketch plane
- std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePnt);
-
SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
-protected:
- /// Checks whether the plane is set in the sketch.
- /// \returns the boolean state
- bool isPlaneSet();
};
#endif
void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
const Standard_Integer aMode)
{
- if ((aMode == 0) || (aMode == SketcherPrs_Tools::Sel_Constraint)) {
- Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10);
- Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint);
- aSelection->Add(aSp);
- }
+// if ((aMode == 0) || (aMode == SketcherPrs_Tools::Sel_Constraint)) {
+// Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10);
+// Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint);
+// aSelection->Add(aSp);
+// }
}
void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)