Salome HOME
Added Angle constraint symbol
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 21 Aug 2015 12:32:13 +0000 (15:32 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 21 Aug 2015 12:32:27 +0000 (15:32 +0300)
src/GeomAPI/GeomAPI_Lin.cpp
src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp
src/SketchPlugin/SketchPlugin_ConstraintAngle.h
src/SketchPlugin/plugin-Sketch.xml
src/SketcherPrs/CMakeLists.txt
src/SketcherPrs/SketcherPrs_Angle.cpp [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_Angle.h
src/SketcherPrs/SketcherPrs_Factory.cpp
src/SketcherPrs/SketcherPrs_LengthDimension.cpp
src/SketcherPrs/SketcherPrs_Radius.cpp

index 79db6e1860b0cb21735d55a06bdd6340767665ce..dba5834abc1b7cb596f0cd088ddb4d954480f437 100644 (file)
@@ -74,10 +74,10 @@ const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::intersect(
   gp_Lin2d aPrjLine1 = ProjLib::Project(aPlane, *MY_LIN);
   gp_Lin2d aPrjLine2 = ProjLib::Project(aPlane, theLine->impl<gp_Lin>());
 
-  IntAna2d_AnaIntersection anInter(aPrjLine1, aPrjLine1);
+  IntAna2d_AnaIntersection anInter(aPrjLine1, aPrjLine2);
   if (!anInter.IsDone() || anInter.IsEmpty())
   return std::shared_ptr<GeomAPI_Pnt>();
-  const gp_Pnt2d& anIntPnt2d = anInter.Point(0).Value();
+  const gp_Pnt2d& anIntPnt2d = anInter.Point(1).Value();
   gp_Pnt aResult = ElSLib::Value(anIntPnt2d.X(), anIntPnt2d.Y(), aPlane);
 
   return std::shared_ptr<GeomAPI_Pnt>(
index c298122ba5299b4766a0b60a437306938a6b1e64..fc2df7237bdaff1f5d4e2bf46c68e13c9aa7b8aa 100644 (file)
@@ -24,6 +24,7 @@ const double tolerance = 1.e-7;
 
 SketchPlugin_ConstraintAngle::SketchPlugin_ConstraintAngle()
 {
+  myFlyoutUpdate = false;
 }
 
 void SketchPlugin_ConstraintAngle::initAttributes()
@@ -31,6 +32,7 @@ void SketchPlugin_ConstraintAngle::initAttributes()
   data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
+  data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId());
 }
 
 void SketchPlugin_ConstraintAngle::execute()
@@ -55,6 +57,11 @@ AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious
   if (!anAIS) {
     anAIS = SketcherPrs_Factory::angleConstraint(this, sketch()->coordinatePlane());
   }
+
+  // Set color from preferences
+  std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color",
+                                                    SKETCH_DIMENSION_COLOR);
+  anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
   return anAIS;
 }
 
@@ -76,6 +83,10 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID)
       double anAngle = calculateAngle();
       aValueAttr->setValue(anAngle);
     }
+  } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) {
+    // Recalculate flyout point in local coordinates
+    std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
   }
 }
 
@@ -124,3 +135,16 @@ double SketchPlugin_ConstraintAngle::calculateAngle()
   anAngle = aDirA->angle(aDirB) * 180.0 / PI;
   return anAngle;
 }
+
+void SketchPlugin_ConstraintAngle::move(double theDeltaX, double theDeltaY)
+{
+  std::shared_ptr<ModelAPI_Data> aData = data();
+  if (!aData->isValid())
+    return;
+
+  myFlyoutUpdate = true;
+  std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = std::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+  aFlyoutAttr->setValue(aFlyoutAttr->x() + theDeltaX, aFlyoutAttr->y() + theDeltaY);
+  myFlyoutUpdate = false;
+}
index 92f5057fb983ba744774ae8c7026a1cdd5b3414d..29f37f82f9678f8ce92356b2969a2a66f16fd725 100644 (file)
@@ -47,11 +47,19 @@ class SketchPlugin_ConstraintAngle : public SketchPlugin_ConstraintBase
   /// Returns the AIS preview
   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
 
+  /// Moves the feature
+  /// \param theDeltaX the delta for X coordinate is moved
+  /// \param theDeltaY the delta for Y coordinate is moved
+  SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+
   /// Calculate current value of the angle
   double calculateAngle();
 
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintAngle();
+
+private:
+  bool myFlyoutUpdate; ///< to avoid cyclic dependencies on automatic updates of flyout point
 };
 
 #endif
index 3c529f6883ab09f4d64dc8d765e12b236d2f8e8e..8418520a855dc6082421f98b200da439cc8b2a53 100644 (file)
           <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
         </shape_selector>
+        <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt"  default="computed" internal="1" obligatory="0"/>
         <doublevalue_editor label="Value" tooltip="Angle" id="ConstraintValue" default="computed" />
         <validator id="PartSet_AngleSelection"/>
       </feature>
index 692fc2205491d01c4ffef281a377aa9f5a54ece6..dac2c7bb506e1956eb655775db7a4806772a35eb 100644 (file)
@@ -18,6 +18,7 @@ SET(PROJECT_HEADERS
        SketcherPrs_LengthDimension.h
        SketcherPrs_Mirror.h
        SketcherPrs_Transformation.h
+       SketcherPrs_Angle.h
 )
 
 SET(PROJECT_SOURCES
@@ -37,6 +38,7 @@ SET(PROJECT_SOURCES
        SketcherPrs_LengthDimension.cpp
        SketcherPrs_Mirror.cpp
        SketcherPrs_Transformation.cpp
+       SketcherPrs_Angle.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/SketcherPrs/SketcherPrs_Angle.cpp b/src/SketcherPrs/SketcherPrs_Angle.cpp
new file mode 100644 (file)
index 0000000..085aa75
--- /dev/null
@@ -0,0 +1,139 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_Angle.cpp
+// Created:     20 August 2015
+// Author:      Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Angle.h"
+#include "SketcherPrs_Tools.h"
+
+#include <SketchPlugin_ConstraintAngle.h>
+#include <SketchPlugin_Constraint.h>
+
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+#include <GeomDataAPI_Point2D.h>
+
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeDouble.h>
+
+#include <TopExp.hxx>
+#include <BRep_Tool.hxx>
+
+#define PI 3.1415926535897932
+
+IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension);
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Angle, AIS_AngleDimension);
+
+
+
+
+
+SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint, 
+                                     const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+: AIS_AngleDimension(gp_Pnt(0,0,0), gp_Pnt(1,0,0), gp_Pnt(0,1,0)), myConstraint(theConstraint), myPlane(thePlane)
+{
+  myAspect = new Prs3d_DimensionAspect();
+  myAspect->MakeArrows3d(false);
+  myAspect->MakeText3d(false);
+  myAspect->MakeTextShaded(false);
+  myAspect->MakeUnitsDisplayed(false);
+  myAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight());
+  myAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize());
+  
+  SetDimensionAspect(myAspect);
+  SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight());
+}
+
+void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+                                const Handle(Prs3d_Presentation)& thePresentation, 
+                                const Standard_Integer theMode)
+{
+  DataPtr aData = myConstraint->data();
+
+  // Flyout point
+  std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = 
+    std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+    (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+  if (!aFlyoutAttr->isInitialized())
+    return; // can not create a good presentation
+
+  std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = myPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
+
+  AttributeRefAttrPtr anAttr1 = aData->refattr(SketchPlugin_Constraint::ENTITY_A());
+  if (!anAttr1->isInitialized())
+    return;
+
+  AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B());
+  if (!anAttr2->isInitialized())
+    return;
+
+  // Get angle edges
+  ObjectPtr aObj1 = anAttr1->object();
+  ObjectPtr aObj2 = anAttr2->object();
+
+  std::shared_ptr<GeomAPI_Shape> aShape1 = SketcherPrs_Tools::getShape(aObj1);
+  std::shared_ptr<GeomAPI_Shape> aShape2 = SketcherPrs_Tools::getShape(aObj2);
+
+  if (!aShape1 && !aShape2)
+    return;
+
+  TopoDS_Shape aTEdge1 = aShape1->impl<TopoDS_Shape>();
+  TopoDS_Shape aTEdge2 = aShape2->impl<TopoDS_Shape>();
+
+  TopoDS_Edge aEdge1 = TopoDS::Edge(aTEdge1);
+  TopoDS_Edge aEdge2 = TopoDS::Edge(aTEdge2);
+  SetMeasuredGeometry(aEdge1, aEdge2);
+
+  // Compute intersection point
+  TopoDS_Vertex aV1, aV2;
+  TopExp::Vertices(aEdge1, aV1, aV2);
+  gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
+  gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
+  std::shared_ptr<GeomAPI_Lin> aL1(new GeomAPI_Lin(aPnt1.X(), aPnt1.Y(), aPnt1.Z(),
+                                                   aPnt2.X(), aPnt2.Y(), aPnt2.Z()));
+  TopExp::Vertices(aEdge2, aV1, aV2);
+  aPnt1 = BRep_Tool::Pnt(aV1);
+  aPnt2 = BRep_Tool::Pnt(aV2);
+  std::shared_ptr<GeomAPI_Lin> aL2(new GeomAPI_Lin(aPnt1.X(), aPnt1.Y(), aPnt1.Z(),
+                                                   aPnt2.X(), aPnt2.Y(), aPnt2.Z()));
+
+  std::shared_ptr<GeomAPI_Pnt> aInter = aL1->intersect(aL2);
+  gp_Pnt aCenter = aInter->impl<gp_Pnt>();
+
+  gp_Pnt aFLyPnt(aFlyoutPnt->x(), aFlyoutPnt->y(), aFlyoutPnt->z());
+  double aDist = aCenter.Distance(aFLyPnt);
+  SetFlyout(aDist);
+
+  // Angle value is in degrees
+  AttributeDoublePtr aVal = aData->real(SketchPlugin_Constraint::VALUE());
+  SetCustomValue(aVal->value() * PI / 180.0);
+
+  AIS_AngleDimension::Compute(thePresentationManager, thePresentation, theMode);
+}
+
+void SketcherPrs_Angle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+                                                   const Standard_Integer theMode)
+{
+  Standard_Integer aMode;
+  switch (theMode) {
+  case 0: // we should use selection of all objects
+    aMode = 0;
+    break;
+  case SketcherPrs_Tools::Sel_Dimension_All:
+    aMode = 0;
+    break;
+  case SketcherPrs_Tools::Sel_Dimension_Line:
+    aMode = 1;
+    break;
+  case SketcherPrs_Tools::Sel_Dimension_Text:
+    aMode = 2;
+    break;
+  default: {
+    // there are own selection modes, so the others should be ignored
+    // otherwise, the text selection appears in the viewer
+    return; 
+  }
+  }
+  AIS_AngleDimension::ComputeSelection(aSelection, aMode);
+}
index 365e82bc2645b40f61e8e8bafa4915ce9ef3605e..d540dbbf5f012a15beb908057395691b309d31ab 100644 (file)
@@ -1,13 +1,53 @@
 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 
 // File:        SketcherPrs_Angle.h
-// Created:     26 March 2015
+// Created:     20 August 2015
 // Author:      Vitaly SMETANNIKOV
 
 
 #ifndef SketcherPrs_Angle_H
 #define SketcherPrs_Angle_H
 
+#include <GeomAPI_Ax3.h>
+#include <ModelAPI_Feature.h>
 
+#include <AIS_AngleDimension.hxx>
+#include <Standard_DefineHandle.hxx>
 
-#endif
\ No newline at end of file
+DEFINE_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension)
+
+/**
+* \ingroup GUI
+* A class for representation of angle constraint
+*/
+class SketcherPrs_Angle : public AIS_AngleDimension
+{
+public:
+  /// Constructor
+  /// \param theConstraint a constraint feature
+  /// \param thePlane a coordinate plane of current sketch
+  Standard_EXPORT SketcherPrs_Angle(ModelAPI_Feature* theConstraint, 
+                        const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
+  DEFINE_STANDARD_RTTI(SketcherPrs_Angle)
+protected:
+  /// Redefinition of virtual function
+  Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+    const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
+
+  /// Redefinition of virtual function
+  Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+    const Standard_Integer aMode);
+
+private:
+  /// Constraint feature
+  ModelAPI_Feature* myConstraint;
+
+  /// Plane of the current sketcher
+  std::shared_ptr<GeomAPI_Ax3> myPlane;
+
+  Handle(Prs3d_DimensionAspect) myAspect;
+};
+
+
+#endif
index 6a8672dac148299007ebcd6aaecfa279154ef1bb..6971d7826829866ea5ff955b1bc14ee27da02a15 100644 (file)
@@ -17,6 +17,7 @@
 #include "SketcherPrs_LengthDimension.h"
 #include "SketcherPrs_Mirror.h"
 #include "SketcherPrs_Transformation.h"
+#include "SketcherPrs_Angle.h"
 
 #define CONSTRAINT_PRS_IMPL(NAME, CLASS) \
 AISObjectPtr SketcherPrs_Factory::NAME(ModelAPI_Feature* theConstraint, \
@@ -37,6 +38,7 @@ CONSTRAINT_PRS_IMPL(tangentConstraint, SketcherPrs_Tangent);
 CONSTRAINT_PRS_IMPL(radiusConstraint, SketcherPrs_Radius);
 CONSTRAINT_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension);
 CONSTRAINT_PRS_IMPL(mirrorConstraint, SketcherPrs_Mirror);
+CONSTRAINT_PRS_IMPL(angleConstraint, SketcherPrs_Angle);
 
 
 AISObjectPtr SketcherPrs_Factory::horisontalConstraint(ModelAPI_Feature* theConstraint,
@@ -74,9 +76,3 @@ AISObjectPtr SketcherPrs_Factory::rotateConstraint(ModelAPI_Feature* theConstrai
   aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); 
   return aAISObj; 
 }
-
-AISObjectPtr SketcherPrs_Factory::angleConstraint(ModelAPI_Feature* theConstraint,
-                                       const std::shared_ptr<GeomAPI_Ax3>& thePlane)
-{
-  return AISObjectPtr(new GeomAPI_AISObject());
-}
index 6e3db92910475a765ffa4e187f4c19a55aadd42f..ea58e65150922a2f14ebdeecaa74a6a7627f3d78 100644 (file)
@@ -55,36 +55,6 @@ void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManage
   gp_Pnt aPnt1, aPnt2;
   if (!getPoints(aPnt1, aPnt2))
     return;
-  //DataPtr aData = myConstraint->data();
-
-  //AttributePtr aFlyOutAttribute = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
-  //if (!aFlyOutAttribute->isInitialized()) {
-  //  return; // not possible to show length because points are not defined
-  //}
-  //std::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = 
-  //  std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFlyOutAttribute);
-  //std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = myPlane->to3D(aFlyOutAttr->x(), aFlyOutAttr->y());
-  //gp_Pnt aFlyPnt = aFlyoutPnt->impl<gp_Pnt>();
-
-  //double aDistance = aPnt1.Distance(aPnt2);
-
-  //double aFlyout = 0;
-  //double aDist = 0.0;
-  //if (aDistance < Precision::Confusion())
-  //  aDist = aPnt1.Distance(aFlyPnt);
-  //else {
-  //  gp_Lin aLine(aPnt1, gp_Vec(aPnt1, aPnt2));
-  //  aDist = aLine.Distance(aFlyPnt);
-  //}
-
-  //gp_XYZ aLineDir = aPnt2.XYZ().Subtracted(aPnt1.XYZ());
-  //gp_XYZ aFOutDir = aFlyPnt.XYZ().Subtracted(aPnt1.XYZ());
-  //gp_XYZ aNorm = myPlane->norm()->xyz()->impl<gp_XYZ>();
-  //if (aLineDir.Crossed(aFOutDir).Dot(aNorm) < 0)
-  //  aDist = -aDist;
-  //aFlyout = aDist;
-
-  //SetFlyout(aFlyout);
   SetFlyout(SketcherPrs_Tools::getFlyoutDistance(myConstraint));
   SetMeasuredGeometry(aPnt1, aPnt2, myPlane->impl<gp_Ax3>());
   AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode);
index c08d7ab9430db8523b308bc025595686ec6a360f..a99bdc9af57f216d671dce5f1b115dd99cd3a9b9 100644 (file)
@@ -53,8 +53,6 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the
   if (!aFlyoutAttr->isInitialized())
     return; // can not create a good presentation
 
-  std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = myPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
-
   // Get circle
   std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
     std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
@@ -85,14 +83,6 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the
   GeomAPI_Circ aCircle(aCenter, aNormal, aRadius);
     
   std::shared_ptr<GeomAPI_Pnt> anAnchor = SketcherPrs_Tools::getAnchorPoint(myConstraint, myPlane);
-  //std::shared_ptr<GeomAPI_Pnt> anAnchor = aCircle.project(aFlyoutPnt);
-  //std::shared_ptr<GeomAPI_XYZ> anAnchorXYZ = anAnchor->xyz();
-  //anAnchorXYZ = anAnchorXYZ->decreased(aCenter->xyz());
-  //std::shared_ptr<GeomAPI_Dir> aDeltaDir(new GeomAPI_Dir(anAnchorXYZ));
-  //const double aDelta = 1e-3;
-  //anAnchor->setX(anAnchor->x() + aDelta * aDeltaDir->x());
-  //anAnchor->setY(anAnchor->y() + aDelta * aDeltaDir->y());
-  //anAnchor->setZ(anAnchor->z() + aDelta * aDeltaDir->z());
 
   SetMeasuredGeometry(aCircle.impl<gp_Circ>(), anAnchor->impl<gp_Pnt>());
   SetCustomValue(aRadius);