]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom
authornds <natalia.donis@opencascade.com>
Wed, 4 Jun 2014 07:54:24 +0000 (11:54 +0400)
committernds <natalia.donis@opencascade.com>
Wed, 4 Jun 2014 07:54:24 +0000 (11:54 +0400)
18 files changed:
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationConstraint.cpp
src/PartSet/PartSet_OperationConstraint.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/PartSet/PartSet_Presentation.cpp [new file with mode: 0644]
src/PartSet/PartSet_Presentation.h [new file with mode: 0644]
src/PartSet/PartSet_TestOCC.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_Constraint.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_ViewerPrs.cpp
src/XGUI/XGUI_ViewerPrs.h

index 569af30e201da0283535823279d020939d5dc2b5..b0006fe5ccc13f9d9ae885c5a4fa09a20b8ae721 100644 (file)
@@ -11,6 +11,7 @@ SET(PROJECT_HEADERS
        PartSet_OperationSketchBase.h
        PartSet_OperationSketch.h
        PartSet_OperationSketchLine.h
+       PartSet_Presentation.h
        PartSet_TestOCC.h
        PartSet_Tools.h
 )
@@ -23,6 +24,7 @@ SET(PROJECT_SOURCES
        PartSet_OperationSketchBase.cpp
        PartSet_OperationSketch.cpp
        PartSet_OperationSketchLine.cpp
+       PartSet_Presentation.cpp
        PartSet_TestOCC.cpp
        PartSet_Tools.cpp
 )
index e9bba754fc817fde2dd8e747ec6310b283d5a8bf..79edcc6a1c598e0d8786581ad2c9de181f87a037 100644 (file)
@@ -7,6 +7,7 @@
 #include <ModuleBase_OperationDescription.h>
 #include <PartSet_Listener.h>
 #include <PartSet_TestOCC.h>
+#include <PartSet_Presentation.h>
 
 #include <ModuleBase_Operation.h>
 #include <ModelAPI_Object.h>
@@ -34,6 +35,7 @@
 #include <GeomAPI_Shape.h>
 
 #include <AIS_ListOfInteractive.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
 
 #include <QObject>
 #include <QMouseEvent>
@@ -394,15 +396,16 @@ void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFea
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   if (isDisplay) {
     boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
-    bool isAISCreated = aDisplayer->Redisplay(theFeature, aPreview ?
-                                           aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
-    if (isAISCreated) {
-      PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
-      if (aSketchOp) {
-        Handle(AIS_InteractiveObject) anAIS = aDisplayer->GetAISObject(theFeature);
-        aSketchOp->correctPresentation(anAIS);
-      }
+    Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+                           theFeature, aPreviewOp->sketch(),
+                           aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+                           aDisplayer->GetAISObject(theFeature));
+
+    int aSelectionMode = -1;
+    if (theFeature->getKind() == "SketchConstraintLength") {
+      aSelectionMode = AIS_DSM_Text;
     }
+    aDisplayer->Redisplay(theFeature, anAIS, aSelectionMode, false);
   }
   else
     aDisplayer->Erase(theFeature, false);
@@ -447,8 +450,12 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
   for (; anIt != aLast; anIt++) {
     boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
     boost::shared_ptr<GeomAPI_Shape> aPreview = (*anIt).second;
-    aDisplayer->Redisplay(aFeature,
-                          aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+    Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+                           aFeature, aPreviewOp->sketch(),
+                           aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+                           aDisplayer->GetAISObject(aFeature));
+    if (!anAIS.IsNull())
+      aDisplayer->Redisplay(aFeature, anAIS, -1, false);
     aDisplayer->ActivateInLocalContext(aFeature, aModes, false);
   }
   aDisplayer->UpdateViewer();
index 9f5e5b503916aecbfc8d9b501a5b0fd041324ceb..6ad9a3108a4741593ab9f6ee8c385130821e9057 100644 (file)
@@ -18,6 +18,7 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeDouble.h>
 
 #include <SketchPlugin_Constraint.h>
 
@@ -91,13 +92,20 @@ void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3
 
   bool isFoundPoint = false;
   gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
+*/
   if (theSelected.empty()) {
-    PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
-    isFoundPoint = true;
+    //PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
+    //isFoundPoint = true;
   }
   else {
     XGUI_ViewerPrs aPrs = theSelected.front();
-    const TopoDS_Shape& aShape = aPrs.shape();
+    boost::shared_ptr<ModelAPI_Feature> aFeature = aPrs.feature();
+
+    setFeature(aFeature);
+    setValue(120);
+    flushUpdated();
+
+    /*const TopoDS_Shape& aShape = aPrs.shape();
     if (!aShape.IsNull()) // the point is selected
     {
       if (aShape.ShapeType() == TopAbs_VERTEX) {
@@ -135,10 +143,10 @@ void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3
           isFoundPoint = true;
         }
       }
-    }
+    }*/
   }
 
-  switch (myPointSelectionMode)
+  /*switch (myPointSelectionMode)
   {
     case SM_FirstPoint: {
       setLinePoint(feature(), aX, anY, LINE_ATTR_START);
@@ -157,8 +165,7 @@ void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3
     break;
     default:
       break;
-  }
-*/
+  }*/
 }
 
 void PartSet_OperationConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
@@ -243,3 +250,25 @@ boost::shared_ptr<ModelAPI_Feature> PartSet_OperationConstraint::createFeature(c
     flushCreated();
   return aNewFeature;
 }
+
+void PartSet_OperationConstraint::setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+  if (!theFeature || theFeature->getKind() != "SketchLine")
+    return;
+
+  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
+          boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+  anAttr->setFeature(theFeature);
+}
+
+void PartSet_OperationConstraint::setValue(const double theValue)
+{
+  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+
+  boost::shared_ptr<ModelAPI_AttributeDouble> anAttr = 
+          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+  anAttr->setValue(theValue);
+
+}
index fe1ea19ce0391aa5279afc75870e9df41a370841..6fc31b709573ae84597c99322e96bb8a4537eee0 100644 (file)
@@ -20,7 +20,7 @@ class PARTSET_EXPORT PartSet_OperationConstraint : public PartSet_OperationSketc
 
 public:
   /// Returns the operation type key
-  static std::string Type() { return "SketchConstraintDistance"; }
+  static std::string Type() { return "SketchConstraintLength"; }
 
 public:
   /// Constructor
@@ -85,6 +85,14 @@ protected:
   /// \returns the created feature
   virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
 
+  /// Set the feature for the constraint
+  /// \param theFeature the line feature
+  void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
+  /// Set the value for the constraint
+  /// \param theValue the constraint value
+  void setValue(const double theValue);
+
 private:
   boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
 };
index ece04ed94168608362b88e0e2fab1eb2a4f5f3d8..abdf6b3c1e40cb10e9dd387dbd5b61460c2a6d5e 100644 (file)
@@ -22,6 +22,8 @@
 #include <AIS_Shape.hxx>
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_InteractiveObject.hxx>
+#include <AIS_DimensionOwner.hxx>
+#include <AIS_LengthDimension.hxx>
 #include <V3d_View.hxx>
 
 #ifdef _DEBUG
@@ -32,9 +34,6 @@
 
 using namespace std;
 
-const Quantity_NameOfColor SKETCH_PLANE_COLOR = Quantity_NOC_CHOCOLATE; /// the plane edge color
-const int SKETCH_WIDTH = 4; /// the plane edge width
-
 PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
                                                     QObject* theParent)
 : PartSet_OperationSketchBase(theId, theParent)
@@ -52,6 +51,7 @@ std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<Mode
     aModes.push_back(TopAbs_FACE);
   else
     aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
+
   return aModes;
 }
 
@@ -96,6 +96,39 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_Vie
   }
 }
 
+#include <QLineEdit>
+void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+                                            const std::list<XGUI_ViewerPrs>& theSelected,
+                                            const std::list<XGUI_ViewerPrs>& theHighlighted)
+{
+  if (!hasSketchPlane()) {
+  }
+  else {
+    if (!theSelected.empty()) {
+      XGUI_ViewerPrs aPrs = theSelected.front();
+      if (!aPrs.owner().IsNull()) {
+        Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aPrs.owner());
+        if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
+          Handle(SelectMgr_SelectableObject) anObject = anOwner->Selectable();
+          double aValue = 0;
+          if (!anObject.IsNull()) {
+            Handle(AIS_LengthDimension) aLenDim = Handle(AIS_LengthDimension)::DownCast(anObject);
+            if (!aLenDim.IsNull())
+              aValue = aLenDim->GetValue();
+          }
+
+          QLineEdit* aLine = new QLineEdit();
+          QPoint aViewPos = theEvent->globalPos();
+          QPoint aLinePos(aViewPos.x(), aViewPos.y());
+          aLine->move(aLinePos);
+          aLine->setText(QString::number(aValue));
+          aLine->show();
+        }
+      }
+    }
+  }
+}
+
 void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
 {
   if (!hasSketchPlane() || !(theEvent->buttons() &  Qt::LeftButton) || myFeatures.empty())
@@ -146,17 +179,6 @@ bool PartSet_OperationSketch::isNestedOperationsEnabled() const
   return hasSketchPlane();
 }
 
-void PartSet_OperationSketch::correctPresentation(Handle(AIS_InteractiveObject) thePresentation)
-{
-  Handle(AIS_Shape) anAIS = Handle(AIS_Shape)::DownCast(thePresentation);
-  if (anAIS.IsNull())
-    return;
-
-  anAIS->SetColor(Quantity_Color(SKETCH_PLANE_COLOR));
-  anAIS->SetWidth(SKETCH_WIDTH);
-  anAIS->Redisplay();
-}
-
 void PartSet_OperationSketch::startOperation()
 {
   if (!feature()) {
index f3b2e77314a8f0d8750a12360be4d29dc47e494f..dd117daf2aaa8768f8cad50783de8911def2b783 100644 (file)
@@ -55,6 +55,15 @@ public:
   virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
                             const std::list<XGUI_ViewerPrs>& theSelected,
                             const std::list<XGUI_ViewerPrs>& theHighlighted);
+  /// Processes the mouse release in the point
+  /// \param theEvent the mouse event
+  /// \param theView a viewer to have the viewer the eye position
+  /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
+  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+                             const std::list<XGUI_ViewerPrs>& theSelected,
+                             const std::list<XGUI_ViewerPrs>& theHighlighted);
+
   /// Gives the current mouse point in the viewer
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
@@ -75,10 +84,6 @@ public:
   /// \return enabled state
   virtual bool isNestedOperationsEnabled() const;
 
-  /// Corrects the presentation settings by the operation
-  /// thePresentation an operation presentation
-  void correctPresentation(Handle_AIS_InteractiveObject thePresentation);
-
 signals:
   /// signal about the sketch plane is selected
   /// \param theX the value in the X direction of the plane
diff --git a/src/PartSet/PartSet_Presentation.cpp b/src/PartSet/PartSet_Presentation.cpp
new file mode 100644 (file)
index 0000000..fa1b21f
--- /dev/null
@@ -0,0 +1,149 @@
+// File:        PartSet_Presentation.h
+// Created:     02 June 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <PartSet_Presentation.h>
+#include <PartSet_Tools.h>
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
+
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
+
+#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Constraint.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_LengthDimension.hxx>
+#include <AIS_Shape.hxx>
+
+#include <gp_Pln.hxx>
+#include <gp_Pnt.hxx>
+
+const Quantity_NameOfColor SKETCH_PLANE_COLOR = Quantity_NOC_CHOCOLATE; /// the plane edge color
+const int SKETCH_WIDTH = 4; /// the plane edge width
+
+Handle(AIS_InteractiveObject) PartSet_Presentation::createPresentation(
+                                         boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                         boost::shared_ptr<ModelAPI_Feature> theSketch,
+                                         const TopoDS_Shape& theShape,
+                                         Handle_AIS_InteractiveObject thePrevPrs)
+{
+  Handle(AIS_InteractiveObject) anAIS;
+
+  if (theFeature->getKind() == "SketchConstraintLength")
+    anAIS = createSketchConstraintLength(theFeature, theSketch, thePrevPrs);
+  else {
+    anAIS = createFeature(theFeature, theShape, thePrevPrs);
+    if (theFeature->getKind() == "Sketch")
+    {
+      Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
+      aShapeAIS->SetColor(Quantity_Color(SKETCH_PLANE_COLOR));
+      aShapeAIS->SetWidth(SKETCH_WIDTH);
+      aShapeAIS->Redisplay();
+    }
+  }
+
+  return anAIS;
+}
+
+Handle(AIS_InteractiveObject) PartSet_Presentation::createFeature(
+                                              boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                              const TopoDS_Shape& theShape,
+                                              Handle_AIS_InteractiveObject thePrevPrs)
+{
+  Handle(AIS_InteractiveObject) anAIS = thePrevPrs;
+  if (!anAIS.IsNull())
+  {
+    Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
+    if (!aShapeAIS.IsNull()) {
+      // if the AIS object is displayed in the opened local context in some mode, additional
+      // AIS sub objects are created there. They should be rebuild for correct selecting.
+      // It is possible to correct it by closing local context before the shape set and opening
+      // after. Another workaround to thrown down the selection and reselecting the AIS.
+      // If there was a problem here, try the first solution with close/open local context.
+      aShapeAIS->Set(theShape);
+      aShapeAIS->Redisplay(Standard_True);
+    }
+  }
+  else
+  {
+    anAIS = new AIS_Shape(theShape);
+  }
+  return anAIS;
+}
+
+Handle(AIS_InteractiveObject) PartSet_Presentation::createSketchConstraintLength(
+                                         boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                         boost::shared_ptr<ModelAPI_Feature> theSketch,
+                                         Handle(AIS_InteractiveObject) thePrevPrs)
+{
+  if (!theFeature || !theSketch)
+    return thePrevPrs;
+
+  boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+  boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+  gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0/*D*/);
+
+  aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
+          boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+  if (!anAttr)
+    return thePrevPrs;
+  boost::shared_ptr<ModelAPI_Feature> aFeature = anAttr->feature();
+  if (!aFeature || aFeature->getKind() != "SketchLine")
+    return thePrevPrs;
+
+  aData = aFeature->data();
+  if (!aData->isValid())
+    return thePrevPrs;
+
+  boost::shared_ptr<GeomDataAPI_Point2D> aPointStart =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+  boost::shared_ptr<GeomDataAPI_Point2D> aPointEnd =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+
+  gp_Pnt aPoint1, aPoint2;
+  PartSet_Tools::ConvertTo3D(aPointStart->x(), aPointStart->y(), theSketch, aPoint1);
+  PartSet_Tools::ConvertTo3D(aPointEnd->x(), aPointEnd->y(), theSketch, aPoint2);
+
+  //Build dimension here
+  gp_Pnt aP1 = aPoint1;
+  gp_Pnt aP2 = aPoint2;
+
+  Handle(AIS_InteractiveObject) anAIS = thePrevPrs;
+  if (anAIS.IsNull())
+  {
+    Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (aP1, aP2, aPlane);
+
+    Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
+    anAspect->MakeArrows3d (Standard_False);
+    anAspect->MakeText3d(false/*is text 3d*/);
+    anAspect->TextAspect()->SetHeight(28);
+    anAspect->MakeTextShaded(false/*is test shaded*/);
+    aLenDim->DimensionAspect()->MakeUnitsDisplayed(false/*is units displayed*/);
+    /*if (isUnitsDisplayed)
+    {
+      aLenDim->SetDisplayUnits (aDimDlg->GetUnits ());
+    }*/
+    aLenDim->SetDimensionAspect (anAspect);
+    aLenDim->SetFlyout(12);
+
+    anAIS = aLenDim;
+  }
+  else {
+    // update presentation
+    Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
+    if (!aDimAIS.IsNull()) {
+      aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane);
+      aDimAIS->Redisplay(Standard_True);
+    }
+  }
+  return anAIS;
+}
diff --git a/src/PartSet/PartSet_Presentation.h b/src/PartSet/PartSet_Presentation.h
new file mode 100644 (file)
index 0000000..ffe8ed4
--- /dev/null
@@ -0,0 +1,44 @@
+// File:        PartSet_Presentation.h
+// Created:     02 Jun 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef PartSet_Presentation_H
+#define PartSet_Presentation_H
+
+#include "PartSet.h"
+
+#include <TopoDS_Shape.hxx>
+
+#include <boost/shared_ptr.hpp>
+
+class ModelAPI_Feature;
+class Handle_AIS_InteractiveObject;
+
+/*!
+ \class PartSet_Presentation
+ * \brief The operation for the sketch feature creation
+*/
+class PARTSET_EXPORT PartSet_Presentation
+{
+public:
+  /// Creates AIS presentation for the given feature
+  /// \param theFeature a feature
+  /// \return the presentation
+  static Handle_AIS_InteractiveObject createPresentation(
+                                              boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                              boost::shared_ptr<ModelAPI_Feature> theSketch,
+                                              const TopoDS_Shape& theShape,
+                                              Handle_AIS_InteractiveObject thePrevPrs);
+protected:
+  static Handle_AIS_InteractiveObject createFeature(
+                                              boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                              const TopoDS_Shape& theShape,
+                                              Handle_AIS_InteractiveObject thePrevPrs);
+
+  static Handle_AIS_InteractiveObject createSketchConstraintLength(
+                                              boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                              boost::shared_ptr<ModelAPI_Feature> theSketch,
+                                              Handle_AIS_InteractiveObject thePrevPrs);
+};
+
+#endif
index 60798a78beae046b0a02c73e2740e7672321e81b..59523f1cc5a717b1880e268a58fa22a86222eac8 100644 (file)
@@ -10,6 +10,7 @@
 #include <XGUI_ViewerPrs.h>
 #include <XGUI_ViewerProxy.h>
 #include <PartSet_OperationSketchLine.h>
+#include <PartSet_Presentation.h>
 
 #include <ModelAPI_Feature.h>
 
@@ -146,7 +147,13 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop)
     boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
 
     XGUI_Displayer* aDisplayer = theWorkshop->displayer();
-    aDisplayer->Redisplay(aFeature, aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+
+    Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+                           aFeature, aSketch,
+                           aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), NULL);
+    if (!anAIS.IsNull())
+      aDisplayer->Redisplay(aFeature, anAIS, -1, false);
+
     std::list<int> aModes;
     aModes.push_back(TopAbs_VERTEX);
     aModes.push_back(TopAbs_EDGE);
@@ -158,9 +165,13 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop)
       aDelta = aDelta - i*2;
       PartSet_OperationSketchLine::setLinePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START);
       PartSet_OperationSketchLine::setLinePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END);
-      boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
 
-      theWorkshop->displayer()->Redisplay(aFeature, aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), true);
+      boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
+      Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+                             aFeature, aSketch,
+                             aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), NULL);
+      if (!anAIS.IsNull())
+        aDisplayer->Redisplay(aFeature, anAIS, -1, true);
 
       int aVal = 90;
       for (int j = 0; j < 10000000; j++)
@@ -174,7 +185,7 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop)
     myTestFeature = aFeature;
 
     std::list<XGUI_ViewerPrs> aPrs;
-    aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape()));
+    aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape(), NULL));
     aDisplayer->SetSelected(aPrs, true);
   }
 }
@@ -192,7 +203,14 @@ void PartSet_TestOCC::changeTestLine(XGUI_Workshop* theWorkshop)
   PartSet_OperationSketchLine::setLinePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END);
   boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
 
-  theWorkshop->displayer()->Redisplay(aFeature, aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), true);
+  Handle(AIS_InteractiveObject) aPrevAIS;
+  boost::shared_ptr<ModelAPI_Feature> aSketch;//NULL
+  Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+                          aFeature, aSketch,
+                          aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+                          aPrevAIS);
+  if (!anAIS.IsNull())
+    theWorkshop->displayer()->Redisplay(aFeature, anAIS, -1, true);
   //std::list<int> aModes;
   //aModes.clear();
   //aModes.push_back(TopAbs_VERTEX);
index 2c7a93b069bab6d65eaaab70c0fd1612d4444d42..596c8675601185d5e1bafde2dabb510259989783 100644 (file)
@@ -103,6 +103,29 @@ void PartSet_Tools::ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr<ModelA
   theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
 }
 
+void PartSet_Tools::ConvertTo3D(const double theX, const double theY,
+                                boost::shared_ptr<ModelAPI_Feature> theSketch,
+                                gp_Pnt& thePoint)
+{
+  if (!theSketch)
+    return;
+
+  boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+
+  boost::shared_ptr<GeomDataAPI_Point> aC = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+  boost::shared_ptr<GeomDataAPI_Dir> aX = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+  boost::shared_ptr<GeomDataAPI_Dir> aY = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
+
+  boost::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(
+    aX->dir()->xyz()->multiplied(theX))->added(aY->dir()->xyz()->multiplied(theY));
+
+  boost::shared_ptr<GeomAPI_Pnt> aPoint = boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
+  thePoint = gp_Pnt(aPoint->x(), aPoint->y(), aPoint->z());
+}
+
 void PartSet_Tools::IntersectLines(double theX0, double theY0, double theX1, double theY1,
                                    double theX2, double theY2, double theX3, double theY3,
                                    double& theX, double& theY)
index 957585b2666dca460af873a780ded28db3174d94..116b58e82c6f9d4839c7be55e3f2b7bb6d5c784c 100644 (file)
@@ -39,6 +39,15 @@ public:
   static void ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr<ModelAPI_Feature> theSketch,
                           Handle(V3d_View) theView, double& theX, double& theY);
 
+  /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
+  /// \param theX the X coordinate
+  /// \param theY the Y coordinate
+  /// \param theSketch the sketch feature
+  /// \param thePoint the 3D point in the viewer
+  static void ConvertTo3D(const double theX, const double theY,
+                          boost::shared_ptr<ModelAPI_Feature> theSketch,
+                          gp_Pnt& thePoint);
+
   /// Returns the point of intersection of the two lines, the first is (v0, v1), the second is (v2, v3),
   /// where vi - {xi,yi}. If the v0 is on the second line, the result is a projection of the v1 to this line
   /// \param theX0 the horizontal coordinate of 0 point
index 9a4d7cf766d9adef77756ab45bf4048da12d68cd..5c0f982e96249ddbc0e79d328200924c9656b1c2 100644 (file)
@@ -40,8 +40,12 @@ SET(PROJECT_LIBRARIES
     ModelAPI
 )
 
+SET(XML_RESOURCES
+  plugin-Sketch.xml
+)
+
 ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
-ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES})
 TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES})
 
 INCLUDE_DIRECTORIES(
@@ -51,9 +55,5 @@ INCLUDE_DIRECTORIES(
   ../GeomDataAPI
 )
 
-SET(XML_RESOURCES
-  plugin-Sketch.xml
-)
-
 INSTALL(TARGETS SketchPlugin DESTINATION plugins)
 INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
index be9b3f8799ba9425ce042767ffab89597fd725d3..be4bb9e41e9cbf1addcf90f3259d3ad00e647871 100644 (file)
@@ -1,7 +1,7 @@
 <plugin>
   <workbench id="Sketch">
     <group id="Basic">
-      <feature id="Sketch" nested="SketchLine SketchConstraintDistance" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
+      <feature id="Sketch" nested="SketchLine SketchConstraintLength" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
         <label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/> 
       <!--icon=":pictures/x_point.png"-->
       </feature>
         <point_selector id="ArcEndPoint" title="End point" tooltip="End point of the arc"/>
       </feature>
       <feature id="SketchConstraintCoincidence" title="Points coincidence" tooltip="Create constraint for the coincidence of two points" internal="1"/>
-      <feature id="SketchConstraintDistance" title="Distance between objects" tooltip="Create constraint for the distance from a point to an object"/>
-      <feature id="SketchConstraintLength" title="Length of a line" tooltip="Create constraint for the given length of a line segment" internal="1"/>
+      <feature id="SketchConstraintDistance" title="Distance between objects" tooltip="Create constraint for the distance from a point to an object" internal="1"/>
+      <feature id="SketchConstraintLength" title="Length of a line" tooltip="Create constraint for the given length of a line segment">
+        <label title="Select a line entity on which to calculate lenght" tooltip="Select a line entity on which to calculate lenght"/>
+      </feature>
       <feature id="SketchConstraintRadius" title="Radius of a circle or an arc" tooltip="Create constraint for the given radius of a circle or an arc" internal="1"/>
       <feature id="SketchConstraintParallel" title="Parallelism of a lines" tooltip="Create constraint defining two parallel lines" internal="1"/>
       <feature id="SketchConstraintPerpendicular" title="Orthgonality of a lines" tooltip="Create constraint defining two perpendicular lines" internal="1"/>
index 2e8a1fae82df22d5e3ba133b0d157b112ea4971e..83bc31671beaec0e09b32b932946e4774d546d8f 100644 (file)
@@ -94,7 +94,7 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr<SketchPlugin_Const
           theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr])
         );
       if (!anAttr) continue;
-      if (anAttr->isFeature())
+      if (anAttr->isFeature() && anAttr->feature())
       { // verify posiible entities
         const std::string& aKind = anAttr->feature()->getKind();
         if (aKind.compare("SketchPoint") == 0)
@@ -149,7 +149,8 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr<SketchPlugin_Const
           theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr])
         );
       if (!anAttr) continue;
-      if (anAttr->isFeature() && anAttr->feature()->getKind().compare("SketchLine") == 0)
+      if (anAttr->isFeature() && anAttr->feature() &&
+          anAttr->feature()->getKind().compare("SketchLine") == 0)
       {
         myAttributesList[aNbLines++] = CONSTRAINT_ATTRIBUTES[indAttr];
         break;
index dd763359d7883e4098b9963236dd2edf8e574648..3a2661e19de5a6c8a68ba95514d2e6e8c1dead0e 100644 (file)
@@ -15,6 +15,7 @@
 #include <AIS_LocalContext.hxx>
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
 
 #include <AIS_Shape.hxx>
 
@@ -64,13 +65,15 @@ std::list<XGUI_ViewerPrs> XGUI_Displayer::GetSelected(const int theShapeTypeToSk
   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
     TopoDS_Shape aShape = aContext->SelectedShape();
+
     if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip)
       continue;
 
     boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(anIO);
     if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
       continue;
-    aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
+    Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
+    aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape, anOwner));
     aPrsFeatures.insert(aFeature);
   }
   return aPresentations;
@@ -91,7 +94,7 @@ std::list<XGUI_ViewerPrs> XGUI_Displayer::GetHighlighted(const int theShapeTypeT
     boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(anIO);
     if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
       continue;
-    aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
+    aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape, NULL));
     aPrsFeatures.insert(aFeature);
   }
 
@@ -118,7 +121,9 @@ void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
 }
 
 bool XGUI_Displayer::Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                               const TopoDS_Shape& theShape, const bool isUpdateViewer)
+                               Handle(AIS_InteractiveObject) theAIS,
+                               const int theSelectionMode,
+                               const bool isUpdateViewer)
 {
   bool isCreated = false;
   Handle(AIS_InteractiveContext) aContext = AISContext();
@@ -131,24 +136,19 @@ bool XGUI_Displayer::Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
     //aContext->SetPixelTolerance(MOUSE_SENSITIVITY_IN_PIXEL);
   }
   // display or redisplay presentation
-  Handle(AIS_Shape) anAIS;
-  if (IsVisible(theFeature)) {
-    anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]);
-    if (!anAIS.IsNull()) {
-      // if the AIS object is displayed in the opened local context in some mode, additional
-      // AIS sub objects are created there. They should be rebuild for correct selecting.
-      // It is possible to correct it by closing local context before the shape set and opening
-      // after. Another workaround to thrown down the selection and reselecting the AIS.
-      // If there was a problem here, try the first solution with close/open local context.
-      anAIS->Set(theShape);
-      anAIS->Redisplay(Standard_True);
-      aContext->RecomputeSelectionOnly(anAIS);
-    }
+  if (IsVisible(theFeature) && !myFeature2AISObjectMap[theFeature].IsNull()) {
+      aContext->RecomputeSelectionOnly(theAIS);
   }
   else {
-    anAIS = new AIS_Shape(theShape);
-    myFeature2AISObjectMap[theFeature] = anAIS;
-    aContext->Display(anAIS, false);
+    myFeature2AISObjectMap[theFeature] = theAIS;
+    if (theSelectionMode < 0)
+    {
+      aContext->Display(theAIS, false);
+    }
+    else
+    {
+      aContext->Display(theAIS, 0, theSelectionMode, false);
+    }
     isCreated = true;
   }
   if (isUpdateViewer)
index dd3ccb4dc016637b6280c2b3e1a53d1080dac886..f9ff755caf5c3bf05e9b3b54ab1fe57a7c8889ae 100644 (file)
@@ -70,12 +70,17 @@ public:
 
   /// Display the shape and activate selection of sub-shapes
   /// \param theFeature a feature instance
-  /// \param theShape a shape
-  /// \param theMode a local selection mode
+  /// \param theAIS an AIS object
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
   /// \returns true if the presentation is created
   bool Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                             const TopoDS_Shape& theShape, const bool isUpdateViewer = true);
+                 Handle(AIS_InteractiveObject) theAIS,
+                 const int theSelectionMode, const bool isUpdateViewer = true);
+
+  /// Redisplay the shape and activate selection of sub-shapes
+  /// \param theFeature a feature instance
+  /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+  //void Redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
 
   /// Display the shape and activate selection of sub-shapes
   /// \param theFeature a feature instance
index 4ab8801aa1f124151bff9b5aa9edbc13267e57af..50cc05d88eaa20ec3524804d5752df06197eb72e 100644 (file)
@@ -4,13 +4,16 @@
 
 #include "XGUI_ViewerPrs.h"
 
+#include "SelectMgr_EntityOwner.hxx"
+
 XGUI_ViewerPrs::XGUI_ViewerPrs()
 {
 }
 
 XGUI_ViewerPrs::XGUI_ViewerPrs(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                               const TopoDS_Shape& theShape)
-: myFeature(theFeature), myShape(theShape)
+                               const TopoDS_Shape& theShape,
+                               Handle(SelectMgr_EntityOwner) theOwner)
+: myFeature(theFeature), myShape(theShape), myOwner(theOwner)
 {
 }
 
@@ -23,14 +26,24 @@ void XGUI_ViewerPrs::setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
   myFeature = theFeature;
 }
 
-void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape)
+boost::shared_ptr<ModelAPI_Feature> XGUI_ViewerPrs::feature() const
 {
-  myShape = theShape;
+  return myFeature;
 }
 
-boost::shared_ptr<ModelAPI_Feature> XGUI_ViewerPrs::feature() const
+void XGUI_ViewerPrs::setOwner(Handle(SelectMgr_EntityOwner) theOwner)
 {
-  return myFeature;
+  myOwner = theOwner;
+}
+
+Handle(SelectMgr_EntityOwner) XGUI_ViewerPrs::owner() const
+{
+  return myOwner;
+}
+
+void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape)
+{
+  myShape = theShape;
 }
 
 const TopoDS_Shape& XGUI_ViewerPrs::shape() const
index 957e4dc7c0a535c0af2c8f1c4fc6ff412fae35de..b0e046b4edc55b1f6f77ef6c19e301a1e0c71fb7 100644 (file)
@@ -9,12 +9,13 @@
 
 #include <boost/shared_ptr.hpp>
 #include <TopoDS_Shape.hxx>
+#include <SelectMgr_EntityOwner.hxx>
 
 class ModelAPI_Feature;
 
 /**\class XGUI_ViewerPrs
  * \ingroup GUI
- * \brief Presentation. Provides container to have feature and the shape
+ * \brief Presentation. Provides container to have feature, shape and/or selection owner.
  */
 class XGUI_EXPORT XGUI_ViewerPrs
 {
@@ -22,8 +23,12 @@ public:
   /// Constructor
   XGUI_ViewerPrs();
   /// Constructor
+  /// \param theFeature a model feature
+  /// \param theShape a viewer shape
+  /// \param theOwner a selection owner
   XGUI_ViewerPrs(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                 const TopoDS_Shape& theShape);
+                 const TopoDS_Shape& theShape,
+                 Handle_SelectMgr_EntityOwner theOwner);
   /// Destructor
   virtual ~XGUI_ViewerPrs();
 
@@ -31,20 +36,29 @@ public:
   /// \param theFeature a feature instance
   void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
 
-  /// Sets the shape
-  /// \param theShape a shape instance
-  void setShape(const TopoDS_Shape& theShape);
-
   /// Returns the feature.
   /// \return a feature instance
   boost::shared_ptr<ModelAPI_Feature> feature() const;
 
+  /// Returns the presentation owner
+  /// \param the owner
+  void setOwner(Handle_SelectMgr_EntityOwner theOwner);
+
+  /// Returns the presentation owner
+  /// \return an owner
+  Handle_SelectMgr_EntityOwner owner() const;
+
+  /// Sets the shape
+  /// \param theShape a shape instance
+  void setShape(const TopoDS_Shape& theShape);
+
   /// Returns the shape
   /// \return a shape instance
   const TopoDS_Shape& shape() const;
 
 private:
   boost::shared_ptr<ModelAPI_Feature> myFeature; /// the feature
+  Handle(SelectMgr_EntityOwner) myOwner; /// the selection owner
   TopoDS_Shape myShape; /// the shape
 };