]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #984: Make trihedron selectable for operations
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 3 Nov 2015 16:03:29 +0000 (19:03 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 3 Nov 2015 16:03:44 +0000 (19:03 +0300)
src/PartSet/PartSet_Tools.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_Selection.cpp

index 57df4e0032216effdd48ec53d3f34061b4a73ba9..ed69af84a7e5a813b6d50583aa0d06d3d8939f6c 100755 (executable)
@@ -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<GeomAPI_Edge> anEdge = std::shared_ptr<GeomAPI_Edge>(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<GeomAPI_Pnt> aPnt1 = anEdge->firstPoint();
+        std::shared_ptr<GeomAPI_Pnt> aPnt2 = anEdge->lastPoint();
+        std::shared_ptr<GeomAPI_Pnt2d> aPnt2d1 = convertTo2D(theSketch, aPnt1);
+        std::shared_ptr<GeomAPI_Pnt2d> aPnt2d2 = convertTo2D(theSketch, aPnt2);
+
+        std::shared_ptr<ModelAPI_Data> aData = aMyFeature->data();
+        std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = 
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::START_ID()));
+        std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = 
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(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<GeomAPI_Edge> anEdge = std::shared_ptr<GeomAPI_Edge>(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<ModelAPI_Result>(theObject);
-      if (anAttr && aRes) {
+      if (!aRes.get()) {
+        aRes = aMyFeature->firstResult();
+      }
+      if (anAttr.get() && aRes.get()) {
         std::shared_ptr<GeomAPI_Shape> 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<ModelAPI_Result>(theObject);
-      if (anAttr && aRes) {
+      if (!aRes.get()) {
+        // If the point is selected not from Result object
+        std::shared_ptr<GeomAPI_Shape> aShape = 
+          std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+        aShape->setImpl(new TopoDS_Shape(theShape));
+
+        std::shared_ptr<GeomAPI_Vertex> aVertex = 
+          std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aShape));
+        std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+
+        std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = convertTo2D(theSketch, aPnt);
+        std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(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<GeomAPI_Shape> aVert(new GeomAPI_Shape);
         aVert->setImpl(new TopoDS_Shape(theShape));
 
index a3a39a870eb319cfe2c893686865c2036c01eb8d..a191509e5bd9723bcfd6ab7844f206a431f8a71f 100644 (file)
@@ -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<Handle(AIS_InteractiveObject)>());
-    }
+  //if (aObjList.isEmpty())
+  //  return;
+  //else {
+  foreach(ObjectPtr aObj, theObjList) {
+    if (myResult2AISObjectMap.contains(aObj))
+      aPrsList.Append(myResult2AISObjectMap[aObj]->impl<Handle(AIS_InteractiveObject)>());
   }
+  //}
+
+  // 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;
 }
index a7eec2af01ce1e5e2e169c6ada9d760e3b746a02..3739668835a4591ee383e78cc81243bf8ded5d46 100644 (file)
@@ -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
index edc1136839354ccbd72ab41671ae32acd2e2f885..49b69883083fb7b99c9857aea76db05c680dc0ad 100644 (file)
 #include <ModelAPI_Feature.h>
 
 #include <AIS_InteractiveContext.hxx>
+#include <AIS_Axis.hxx>
+#include <AIS_Point.hxx>
+#include <Geom_Line.hxx>
+#include <BRep_Builder.hxx>
+#include <TopoDS_Edge.hxx>
+#include <Geom_Point.hxx>
+#include <Geom_TrimmedCurve.hxx>
+#include <Prs3d_DatumAspect.hxx>
 
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 #include <StdSelect_BRepOwner.hxx>
@@ -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);