From 19fc4aa0b7041736b4a099bb1fc3ddc89695a338 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 3 Nov 2015 19:03:29 +0300 Subject: [PATCH] Issue #984: Make trihedron selectable for operations --- src/PartSet/PartSet_Tools.cpp | 65 ++++++++++++++++++++++++++++++++--- src/XGUI/XGUI_Displayer.cpp | 58 ++++++++++++++++++++++--------- src/XGUI/XGUI_Displayer.h | 3 ++ src/XGUI/XGUI_Selection.cpp | 36 ++++++++++++++++++- 4 files changed, 141 insertions(+), 21 deletions(-) diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 57df4e003..ed69af84a 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -431,12 +431,44 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(theShape), aStart, aEnd); GeomAdaptor_Curve aAdaptor(aCurve); + std::shared_ptr anEdge = std::shared_ptr(new GeomAPI_Edge); + anEdge->setImpl(new TopoDS_Shape(theShape)); if (aAdaptor.GetType() == GeomAbs_Line) { // Create line aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID()); + if (!theObject.get()) { + // There is no selected result + std::shared_ptr aPnt1 = anEdge->firstPoint(); + std::shared_ptr aPnt2 = anEdge->lastPoint(); + std::shared_ptr aPnt2d1 = convertTo2D(theSketch, aPnt1); + std::shared_ptr aPnt2d2 = convertTo2D(theSketch, aPnt2); + + std::shared_ptr aData = aMyFeature->data(); + std::shared_ptr aPoint1 = + std::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aPoint2 = + std::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::END_ID())); + + aPoint1->setValue(aPnt2d1); + aPoint2->setValue(aPnt2d2); + + // If this is an axis then its name has to be changed correspondently + std::string aSuffix = ""; + bool aXdir = fabs(aPnt1->x() - aPnt2->x()) > Precision::Confusion(); + bool aYdir = fabs(aPnt1->y() - aPnt2->y()) > Precision::Confusion(); + bool aZdir = fabs(aPnt1->z() - aPnt2->z()) > Precision::Confusion(); + if (aXdir && (!aYdir) && (!aZdir)) + aSuffix = "X"; + else if ((!aXdir) && aYdir && (!aZdir)) + aSuffix = "Y"; + else if ((!aXdir) && (!aYdir) && aZdir) + aSuffix = "Z"; + if (aSuffix.length() > 0) + aData->setName("Axis_" + aSuffix); + aMyFeature->execute(); + + } } else if (aAdaptor.GetType() == GeomAbs_Circle) { - std::shared_ptr anEdge = std::shared_ptr(new GeomAPI_Edge); - anEdge->setImpl(new TopoDS_Shape(theShape)); if (anEdge->isArc()) { // Create arc aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID()); @@ -453,7 +485,10 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); ResultPtr aRes = std::dynamic_pointer_cast(theObject); - if (anAttr && aRes) { + if (!aRes.get()) { + aRes = aMyFeature->firstResult(); + } + if (anAttr.get() && aRes.get()) { std::shared_ptr anEdge(new GeomAPI_Shape); anEdge->setImpl(new TopoDS_Shape(theShape)); @@ -480,7 +515,29 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); ResultPtr aRes = std::dynamic_pointer_cast(theObject); - if (anAttr && aRes) { + if (!aRes.get()) { + // If the point is selected not from Result object + std::shared_ptr aShape = + std::shared_ptr(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(theShape)); + + std::shared_ptr aVertex = + std::shared_ptr(new GeomAPI_Vertex(aShape)); + std::shared_ptr aPnt = aVertex->point(); + + std::shared_ptr aPnt2d = convertTo2D(theSketch, aPnt); + std::shared_ptr aPoint = + std::dynamic_pointer_cast(aData->attribute(SketchPlugin_Point::COORD_ID())); + aPoint->setValue(aPnt2d); + if ((aPnt->x() < Precision::Confusion()) && + (aPnt->y() < Precision::Confusion()) && + (aPnt->z() < Precision::Confusion())) + aData->setName("Origin"); + + aMyFeature->execute(); + aRes = aMyFeature->firstResult(); + } + if (anAttr.get() && aRes.get()) { std::shared_ptr aVert(new GeomAPI_Shape); aVert->setImpl(new TopoDS_Shape(theShape)); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index a3a39a870..a191509e5 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -364,6 +364,10 @@ void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer) void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList, const bool theUpdateViewer) { + //Handle(AIS_InteractiveObject) aTriehedron = getTrihedron(); + //if (!aTriehedron.IsNull()) + // deactivateAIS(aTriehedron); + QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end(); for (; anIt != aLast; anIt++) { deactivate(*anIt, false); @@ -438,14 +442,22 @@ void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrL Handle(AIS_InteractiveObject) anAISIO; AIS_ListOfInteractive aPrsList; - if (theObjList.isEmpty()) - return; - else { - foreach(ObjectPtr aObj, theObjList) { - if (myResult2AISObjectMap.contains(aObj)) - aPrsList.Append(myResult2AISObjectMap[aObj]->impl()); - } + //if (aObjList.isEmpty()) + // return; + //else { + foreach(ObjectPtr aObj, theObjList) { + if (myResult2AISObjectMap.contains(aObj)) + aPrsList.Append(myResult2AISObjectMap[aObj]->impl()); } + //} + + // Add trihedron because it has to partisipate in selection + Handle(AIS_InteractiveObject) aTrihedron = getTrihedron(); + if (!aTrihedron.IsNull()) + aPrsList.Append(aTrihedron); + + if (aPrsList.Extent() == 0) + return; AIS_ListIteratorOfListOfInteractive aLIt(aPrsList); bool isActivationChanged = false; @@ -454,6 +466,10 @@ void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrL if (activate(anAISIO, myActiveSelectionModes, false)) isActivationChanged = true; } + if (!aTrihedron.IsNull()) { + foreach(int aMode, myActiveSelectionModes) + aContext->SetSelectionSensitivity(aTrihedron, aMode, 8); + } // VSV It seems that there is no necessity to update viewer on activation //if (theUpdateViewer && isActivationChanged) // updateViewer(); @@ -556,7 +572,16 @@ bool XGUI_Displayer::eraseAll(const bool theUpdateViewer) void XGUI_Displayer::deactivateTrihedron() const { - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + Handle(AIS_InteractiveObject) aTrihedron = getTrihedron(); + if (!aTrihedron.IsNull()) { + Handle(AIS_InteractiveContext) aContext = AISContext(); + aContext->Deactivate(aTrihedron); + } +} + +Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); if (!aContext.IsNull()) { AIS_ListOfInteractive aList; aContext->DisplayedObjects(aList, true); @@ -564,15 +589,16 @@ void XGUI_Displayer::deactivateTrihedron() const for (aIt.Initialize(aList); aIt.More(); aIt.Next()) { Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aIt.Value()); if (!aTrihedron.IsNull()) { - aContext->Deactivate(aTrihedron); + return aTrihedron; } } } + return Handle(AIS_InteractiveObject)(); } void XGUI_Displayer::openLocalContext() { - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + Handle(AIS_InteractiveContext) aContext = AISContext(); // Open local context if there is no one if (!aContext.IsNull() && !aContext->HasOpenedContext()) { // Preserve selected objects @@ -590,7 +616,7 @@ void XGUI_Displayer::openLocalContext() //aContext->ClearCurrents(); aContext->OpenLocalContext(); - deactivateTrihedron(); + //deactivateTrihedron(); //aContext->NotUseDisplayedObjects(); //myUseExternalObjects = false; @@ -732,7 +758,7 @@ void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO, void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const { - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + Handle(AIS_InteractiveContext) aContext = AISContext(); if (!aContext.IsNull()) { if (theMode == -1) aContext->Deactivate(theIO); @@ -752,7 +778,7 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); if (!aContext.IsNull() && !aContext->HasOpenedContext()) { aContext->OpenLocalContext(); - deactivateTrihedron(); + //deactivateTrihedron(); aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0); aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0); } @@ -1007,8 +1033,8 @@ bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, // trihedron AIS check should be after the AIS loading. // If it is not loaded, it is steel selectable in the viewer. - Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO); - if (aTrihedron.IsNull()) { + //Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO); + //if (aTrihedron.IsNull()) { //aContext->Load(anAISIO, -1, true); // In order to clear active modes list if (theModes.size() == 0) { @@ -1022,7 +1048,7 @@ bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, isActivationChanged = true; } } - } + //} } return isActivationChanged; } diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index a7eec2af0..373966883 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -227,6 +227,9 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// \param theUpdateViewer update viewer flag /// \return previously defined color on the object QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true); + + /// Returns Trihedron object if it is displayed + Handle(AIS_InteractiveObject) getTrihedron() const; /// Converts shape type (TopAbs_ShapeEnum) to selection mode /// \param theShapeType a shape type from TopAbs_ShapeEnum diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index edc113683..49b698830 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -13,6 +13,14 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -120,7 +128,33 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrs& thePrs, TopoDS_Shape aShape = aBRO->Shape().Located (aBRO->Location() * aBRO->Shape().Location()); if (!aShape.IsNull()) thePrs.setShape(aShape); - } + } else { + // Fill by trihedron shapes + Handle(AIS_Axis) aAxis = Handle(AIS_Axis)::DownCast(anIO); + if (!aAxis.IsNull()) { + // an Axis from Trihedron + Handle(Geom_Line) aLine = aAxis->Component(); + Handle(Prs3d_DatumAspect) DA = aAxis->Attributes()->DatumAspect(); + Handle(Geom_TrimmedCurve) aTLine = new Geom_TrimmedCurve(aLine, 0, DA->FirstAxisLength()); + + BRep_Builder aBuilder; + TopoDS_Edge aEdge; + aBuilder.MakeEdge(aEdge, aTLine, Precision::Confusion()); + if (!aEdge.IsNull()) + thePrs.setShape(aEdge); + } else { + Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast(anIO); + if (!aPoint.IsNull()) { + // A point from trihedron + Handle(Geom_Point) aPnt = aPoint->Component(); + BRep_Builder aBuilder; + TopoDS_Vertex aVertex; + aBuilder.MakeVertex(aVertex, aPnt->Pnt(), Precision::Confusion()); + if (!aVertex.IsNull()) + thePrs.setShape(aVertex); + } + } + } XGUI_Displayer* aDisplayer = myWorkshop->displayer(); ObjectPtr aFeature = aDisplayer->getObject(anIO); -- 2.39.2