]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1315 Middle point constraint problem
authornds <nds@opencascade.com>
Mon, 29 Feb 2016 12:43:32 +0000 (15:43 +0300)
committernds <nds@opencascade.com>
Mon, 29 Feb 2016 12:43:59 +0000 (15:43 +0300)
14 files changed:
src/SketchPlugin/SketchPlugin_ConstraintCollinear.cpp
src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp
src/SketchPlugin/SketchPlugin_ConstraintMiddle.h
src/SketcherPrs/CMakeLists.txt
src/SketcherPrs/SketcherPrs_Collinear.cpp
src/SketcherPrs/SketcherPrs_Collinear.h
src/SketcherPrs/SketcherPrs_Factory.cpp
src/SketcherPrs/SketcherPrs_Factory.h
src/SketcherPrs/SketcherPrs_Middle.cpp
src/SketcherPrs/SketcherPrs_Middle.h
src/SketcherPrs/SketcherPrs_Tools.cpp
src/SketcherPrs/SketcherPrs_Tools.h
src/SketcherPrs/icons/collinear.png [new file with mode: 0755]
src/SketcherPrs/icons/middlepoint.png [new file with mode: 0755]

index d7c7e07c32df00659cea97abb2e61675743d0093..6e175a9d387ab0fabe0960c35779095fd3301563 100644 (file)
@@ -6,6 +6,8 @@
 
 #include "SketchPlugin_ConstraintCollinear.h"
 
+#include "SketcherPrs_Factory.h"
+
 SketchPlugin_ConstraintCollinear::SketchPlugin_ConstraintCollinear()
 {
 }
@@ -25,10 +27,8 @@ AISObjectPtr SketchPlugin_ConstraintCollinear::getAISObject(AISObjectPtr thePrev
   if (!sketch())
     return thePrevious;
 
-  AISObjectPtr anAIS;
-  // TODO
-  //AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(),
-  //                                                              thePrevious);
+  AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(),
+                                                                thePrevious);
   return anAIS;
 }
 
index 7112d440101f6283295d6e73372595b221e69949..31fc3f1da64ecc9fa2b6868648aa003dea155051 100644 (file)
@@ -6,6 +6,8 @@
 
 #include "SketchPlugin_ConstraintMiddle.h"
 
+#include "SketcherPrs_Factory.h"
+
 SketchPlugin_ConstraintMiddle::SketchPlugin_ConstraintMiddle()
 {
 }
@@ -25,10 +27,8 @@ AISObjectPtr SketchPlugin_ConstraintMiddle::getAISObject(AISObjectPtr thePreviou
   if (!sketch())
     return thePrevious;
 
-  AISObjectPtr anAIS;
-  // TODO
-  //AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(),
-  //                                                              thePrevious);
+  AISObjectPtr anAIS = SketcherPrs_Factory::middleConstraint(this, sketch()->coordinatePlane(),
+                                                             thePrevious);
   return anAIS;
 }
 
index 9cf7b866f8561b7ea80e4b7311171c33a743d6de..148942a5bf9224d782795cbe7953f3b604726b29 100644 (file)
@@ -13,7 +13,7 @@
 
 /** \class SketchPlugin_ConstraintMiddle
  *  \ingroup Plugins
- *  \brief Feature for creation of a new constraintwhich places a point in the middle of a line
+ *  \brief Feature for creation of a new constraint which places a point in the middle of a line
  *
  *  This constraint has two attributes:
  *  SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
index 221e5a1b3b84d17da22c92586382fdb2ebf73a18..55d73ee502460471b38236427dd9eca50ad2ae6f 100644 (file)
@@ -73,6 +73,7 @@ ENDIF()
 
 
 SET(PROJECT_PICTURES
+    icons/collinear.png
     icons/parallel.png
     icons/perpendicular.png
     icons/anchor.png
@@ -80,6 +81,7 @@ SET(PROJECT_PICTURES
     icons/vertical.png
     icons/equal.png
     icons/tangent.png
+    icons/middlepoint.png
     icons/mirror.png
     icons/rotate.png
     icons/translate.png
index 57cf26413fa92fd17caaa4c311e69c13c4bf4138..64e027394b0269b4bf915715f3698a68d922ee80 100755 (executable)
@@ -68,18 +68,8 @@ void SketcherPrs_Collinear::drawLines(const Handle(Prs3d_Presentation)& thePrs,
   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
   aGroup->SetPrimitivesAspect(aLineAspect);
 
-  // Draw first line
-  ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
-  std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aObj);
-  if (aLine.get() == NULL)
-    return;
-  drawShape(aLine, thePrs);
-
-  // Draw second line
-  aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
-  aLine = SketcherPrs_Tools::getShape(aObj);
-  if (aLine.get() == NULL)
-    return;
-  drawShape(aLine, thePrs);
+  // Draw constrained lines
+  addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
+  addLine(aGroup, SketchPlugin_Constraint::ENTITY_B());
 }
 
index e48065cd6252e5a82d38e488ca8dda33946ef0ab..e43fdac89aa4423b445ab2d5fb941340dc85ab7c 100755 (executable)
@@ -1,7 +1,7 @@
 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 
 // File:        SketcherPrs_Collinear.h
-// Created:     29 February 2016
+// Created:     29 Feb 2016
 // Author:      Natalia ERMOLAEVA
 
 #ifndef SketcherPrs_Collinear_H
@@ -35,7 +35,7 @@ public:
                                const std::shared_ptr<GeomAPI_Ax3>& thePlane);
 protected:
 
-  virtual const char* iconName() const { return "equal.png"; }
+  virtual const char* iconName() const { return "collinear.png"; }
 
   virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
 
index 9ab167332603e1e0218ade9ae98f18700e592638..449c3c24ae7577ff0c55de30a4439727adea1a78 100644 (file)
@@ -7,6 +7,7 @@
 #include "SketcherPrs_Factory.h"
 
 #include "SketcherPrs_Coincident.h"
+#include "SketcherPrs_Collinear.h"
 #include "SketcherPrs_Parallel.h"
 #include "SketcherPrs_Perpendicular.h"
 #include "SketcherPrs_Rigid.h"
@@ -15,6 +16,7 @@
 #include "SketcherPrs_Tangent.h"
 #include "SketcherPrs_Radius.h"
 #include "SketcherPrs_LengthDimension.h"
+#include "SketcherPrs_Middle.h"
 #include "SketcherPrs_Mirror.h"
 #include "SketcherPrs_Transformation.h"
 #include "SketcherPrs_Angle.h"
@@ -39,6 +41,7 @@ AISObjectPtr SketcherPrs_Factory::NAME(ModelAPI_Feature* theConstraint, \
 }
 
 CONSTRAINT_PRS_IMPL(coincidentConstraint, SketcherPrs_Coincident);
+CONSTRAINT_PRS_IMPL(collinearConstraint, SketcherPrs_Collinear);
 CONSTRAINT_PRS_IMPL(parallelConstraint, SketcherPrs_Parallel);
 CONSTRAINT_PRS_IMPL(perpendicularConstraint, SketcherPrs_Perpendicular);
 CONSTRAINT_PRS_IMPL(rigidConstraint, SketcherPrs_Rigid);
@@ -46,6 +49,7 @@ CONSTRAINT_PRS_IMPL(equalConstraint, SketcherPrs_Equal);
 CONSTRAINT_PRS_IMPL(tangentConstraint, SketcherPrs_Tangent);
 CONSTRAINT_PRS_IMPL(radiusConstraint, SketcherPrs_Radius);
 CONSTRAINT_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension);
+CONSTRAINT_PRS_IMPL(middleConstraint, SketcherPrs_Middle);
 CONSTRAINT_PRS_IMPL(mirrorConstraint, SketcherPrs_Mirror);
 CONSTRAINT_PRS_IMPL(angleConstraint, SketcherPrs_Angle);
 
index 485c5a6fe0457622b2b2e7a30531fa1fbef1122d..2f43622b04aaa398db891710f16a995ab0e18d76 100644 (file)
@@ -30,6 +30,11 @@ public:
   /// \param thePlane the current sketch plane
   GET_CONSTRAINT_PRS(coincidentConstraint)
 
+  /// Creates collinear constraint presentation
+  /// \param theConstraint the constraint
+  /// \param thePlane the current sketch plane
+  GET_CONSTRAINT_PRS(collinearConstraint)
+
   /// Creates parallel constraint presentation
   /// \param theConstraint the constraint
   /// \param thePlane the current sketch plane
@@ -75,6 +80,11 @@ public:
   /// \param thePlane the current sketch plane
   GET_CONSTRAINT_PRS(lengthDimensionConstraint)
 
+  /// Creates middle constraint presentation
+  /// \param theConstraint the constraint
+  /// \param thePlane the current sketch plane
+  GET_CONSTRAINT_PRS(middleConstraint)
+
   /// Creates mirror constraint presentation
   /// \param theConstraint the constraint
   /// \param thePlane the current sketch plane
index a588752a716f06748612a9def703458b22dcddc9..eaba7173302f9d565768f65e4a18acec4ea4cebf 100755 (executable)
@@ -27,7 +27,6 @@ SketcherPrs_Middle::SketcherPrs_Middle(ModelAPI_Feature* theConstraint,
 {
   myPntArray = new Graphic3d_ArrayOfPoints(2);
   myPntArray->AddVertex(0., 0., 0.);
-  myPntArray->AddVertex(0., 0., 0.);
 }  
 
 bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
@@ -38,8 +37,10 @@ bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
   ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
   ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
 
-  aReadyToDisplay = SketcherPrs_Tools::getShape(aObj1).get() != NULL &&
-                    SketcherPrs_Tools::getShape(aObj2).get() != NULL;
+  // one object is a feature Line, other object is a point result. We check shape of point result
+  aReadyToDisplay = aObj1.get() && aObj2.get() &&
+                    (SketcherPrs_Tools::getShape(aObj1).get() != NULL ||
+                     SketcherPrs_Tools::getShape(aObj2).get() != NULL);
 
   return aReadyToDisplay;
 }
@@ -48,16 +49,30 @@ bool SketcherPrs_Middle::updatePoints(double theStep) const
 {
   if (!IsReadyToDisplay(myConstraint, myPlane))
     return false;
-
-  ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
-  ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+  ObjectPtr aPointObject;
+
+  // find a line result to set middle symbol near it
+  AttributePtr anAttribute = SketcherPrs_Tools::getAttribute(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+  if (!anAttribute.get()) {
+    ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+    std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
+    if (aShape.get() && aShape->isEdge())
+      aPointObject = aObj;
+  }
+  if (!aPointObject.get()) {
+    ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+    std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
+    if (aShape.get() && aShape->isEdge())
+      aPointObject = aObj;
+  }
+
+  if (!aPointObject.get())
+    return false;
 
   // Set points of the presentation
   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
-  gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
-  gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
+  gp_Pnt aP1 = aMgr->getPosition(aPointObject, this, theStep);
   myPntArray->SetVertice(1, aP1);
-  myPntArray->SetVertice(2, aP2);
   return true;
 }
 
@@ -68,18 +83,31 @@ void SketcherPrs_Middle::drawLines(const Handle(Prs3d_Presentation)& thePrs, Qua
   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
   aGroup->SetPrimitivesAspect(aLineAspect);
 
-  // Draw first line
-  ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
-  std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aObj);
-  if (aLine.get() == NULL)
-    return;
-  drawShape(aLine, thePrs);
-
-  // Draw second line
-  aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
-  aLine = SketcherPrs_Tools::getShape(aObj);
-  if (aLine.get() == NULL)
-    return;
-  drawShape(aLine, thePrs);
+  // Draw objects
+  ObjectPtr aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+  drawLine(thePrs, theColor, aObject);
+
+  aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+  drawLine(thePrs, theColor, aObject);
+}
+
+void SketcherPrs_Middle::drawLine(const Handle(Prs3d_Presentation)& thePrs,
+                                  Quantity_Color theColor, const ObjectPtr& theObject) const
+{
+  FeaturePtr aLineFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+  if (aLineFeature.get()) {
+    std::list<ResultPtr> aResults = aLineFeature->results();
+    if (aResults.size() == 1) {
+      ResultPtr aResult = aResults.front();
+      std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aResult);
+      if (aLine.get() != NULL)
+        drawShape(aLine, thePrs);
+    }
+  }
+  else {
+    std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(theObject);
+    if (aLine.get() != NULL)
+      drawShape(aLine, thePrs);
+  }
 }
 
index fb72cec2917a32de400c39295d3bc69f253d1c5f..10d22ba868d476c8c413fdda266cf75150b6887c 100755 (executable)
@@ -35,13 +35,17 @@ public:
                                const std::shared_ptr<GeomAPI_Ax3>& thePlane);
 protected:
 
-  virtual const char* iconName() const { return "equal.png"; }
+  virtual const char* iconName() const { return "middlepoint.png"; }
 
   virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
 
   /// Update myPntArray according to presentation positions
   /// \return true in case of success
   virtual bool updatePoints(double theStep) const;
+
+  /// Draw shape of the object. Find shape result if the object is feature
+  void drawLine(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor,
+                const ObjectPtr& theObject) const;
 };
 
 #endif
\ No newline at end of file
index 78b521957ba85a23359bbb5c29d62e09f7e75cd9..d481dcbe7fc946ae64f438118e7a66662c9bb73d 100644 (file)
@@ -35,6 +35,13 @@ static const Standard_ExtCharacter MySigmaSymbol(0x03A3);
 
 namespace SketcherPrs_Tools {
 
+AttributePtr getAttribute(ModelAPI_Feature* theFeature, const std::string& theAttrName)
+{
+  std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = aData->refattr(theAttrName);
+  return !anAttr->isObject() ? anAttr->attr() : AttributePtr();
+}
+
 ObjectPtr getResult(ModelAPI_Feature* theFeature, const std::string& theAttrName)
 {
   std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
index f490898f4c3018a16fc86e1a25b6f97f4a49fb53..1af656aee3f2bc19dffa01065e6787bf0e1c26c9 100644 (file)
@@ -12,6 +12,7 @@
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Ax3.h>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_Attribute.h>
 #include <ModelAPI_Feature.h>
 #include <string>
 
@@ -40,6 +41,12 @@ namespace SketcherPrs_Tools {
     Sel_Dimension_Text
   };
 
+  /// Returns attribute object referenced by feature
+  /// \param theFeature a feature
+  /// \param theAttrName an attribute name
+  SKETCHERPRS_EXPORT AttributePtr getAttribute(ModelAPI_Feature* theFeature,
+                                               const std::string& theAttrName);
+
   /// Returns result object referenced by feature
   /// \param theFeature a feature
   /// \param theAttrName an attribute name
diff --git a/src/SketcherPrs/icons/collinear.png b/src/SketcherPrs/icons/collinear.png
new file mode 100755 (executable)
index 0000000..4a7283b
Binary files /dev/null and b/src/SketcherPrs/icons/collinear.png differ
diff --git a/src/SketcherPrs/icons/middlepoint.png b/src/SketcherPrs/icons/middlepoint.png
new file mode 100755 (executable)
index 0000000..c0040d3
Binary files /dev/null and b/src/SketcherPrs/icons/middlepoint.png differ