]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1664: In the Sketcher, add the function Split a segment. Correction of circle...
authornds <nds@opencascade.com>
Tue, 26 Jul 2016 06:28:00 +0000 (09:28 +0300)
committernds <nds@opencascade.com>
Tue, 26 Jul 2016 06:28:00 +0000 (09:28 +0300)
src/GeomAPI/GeomAPI_Circ.cpp
src/Model/Model_AttributeReference.cpp
src/PartSet/PartSet_WidgetSubShapeSelector.cpp
src/PartSet/PartSet_WidgetSubShapeSelector.h
src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp
src/SketchPlugin/SketchPlugin_ConstraintSplit.h
src/SketchPlugin/plugin-Sketch.xml

index c7c4573f0df838d72e73172cc011f5321613762e..4346391bd457e6cec033ed857763870f12106d63 100644 (file)
@@ -70,11 +70,11 @@ const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::project(
   GeomAPI_ProjectPointOnCurve aProj(aPoint, aCircle);
   Standard_Integer aNbPoint = aProj.NbPoints();
   if (aNbPoint > 0) {
-    double aMinDistance = 0, aDistance;
+    double aMinDistance = Precision::Infinite(), aDistance;
     for (Standard_Integer j = 1; j <= aNbPoint; j++) {
       gp_Pnt aNewPoint = aProj.Point(j);
       aDistance = aNewPoint.Distance(aPoint);
-      if (!aMinDistance || aDistance < aMinDistance) {
+      if (aDistance < aMinDistance) {
         aMinDistance = aDistance;
         aResult = std::shared_ptr<GeomAPI_Pnt>(
             new GeomAPI_Pnt(aNewPoint.X(), aNewPoint.Y(), aNewPoint.Z()));
index b1707c006857736f8bfb9f5bcc6fd88e028141a4..dc1a3994d22861431126c4f20be293de14731417 100644 (file)
@@ -25,7 +25,6 @@ void Model_AttributeReference::setValue(ObjectPtr theObject)
   //  return;
   ObjectPtr aValue = value();
   if (!myIsInitialized || aValue != theObject) {
-    myIsInitialized = true;
     REMOVE_BACK_REF(aValue);
 
     TDF_Label anObjLab;
@@ -64,34 +63,31 @@ void Model_AttributeReference::setValue(ObjectPtr theObject)
 
 ObjectPtr Model_AttributeReference::value()
 {
-  if (isInitialized()) {
-    Handle(TDataStd_Comment) aDocID;
-    if (myRef->Label().FindAttribute(TDataStd_Comment::GetID(), aDocID)) { // external ref
-      int anID = atoi(TCollection_AsciiString(aDocID->Get()).ToCString());
-      DocumentPtr aRefDoc = Model_Application::getApplication()->document(anID);
-      if (aRefDoc.get()) {
-        Handle(TDataStd_AsciiString) anEntry;
-        if (myRef->Label().FindAttribute(TDataStd_AsciiString::GetID(), anEntry)) {
-          std::shared_ptr<Model_Document> aDR = std::dynamic_pointer_cast<Model_Document>(aRefDoc);
-          TDF_Label aRefLab;
-          TDF_Tool::Label(aDR->objects()->featuresLabel().Data(), anEntry->Get().ToCString(), aRefLab);
-          if (!aRefLab.IsNull()) {
-            return aDR->objects()->object(aRefLab);
-          }
+  Handle(TDataStd_Comment) aDocID;
+  if (myRef->Label().FindAttribute(TDataStd_Comment::GetID(), aDocID)) { // external ref
+    int anID = atoi(TCollection_AsciiString(aDocID->Get()).ToCString());
+    DocumentPtr aRefDoc = Model_Application::getApplication()->document(anID);
+    if (aRefDoc.get()) {
+      Handle(TDataStd_AsciiString) anEntry;
+      if (myRef->Label().FindAttribute(TDataStd_AsciiString::GetID(), anEntry)) {
+        std::shared_ptr<Model_Document> aDR = std::dynamic_pointer_cast<Model_Document>(aRefDoc);
+        TDF_Label aRefLab;
+        TDF_Tool::Label(aDR->objects()->featuresLabel().Data(), anEntry->Get().ToCString(), aRefLab);
+        if (!aRefLab.IsNull()) {
+          return aDR->objects()->object(aRefLab);
         }
       }
-    } else { // internal ref
-      std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
-          owner()->document());
-      if (aDoc) {
-        TDF_Label aRefLab = myRef->Get();
-        if (!aRefLab.IsNull()) {  // it may happen with old document, issue #285
-          return aDoc->objects()->object(aRefLab);
-        }
+    }
+  } else { // internal ref
+    std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
+        owner()->document());
+    if (aDoc) {
+      TDF_Label aRefLab = myRef->Get();
+      if (!aRefLab.IsNull()) {  // it may happen with old document, issue #285
+        return aDoc->objects()->object(aRefLab);
       }
     }
   }
-  // not initialized
   return FeaturePtr();
 }
 
index bdb039aad75c63fc8d111a42a2bea30246de16a1..72e0738bf063600a6a2ac41ba643dbdc3a9fe028 100755 (executable)
@@ -22,6 +22,7 @@
 #include <ModelGeomAlgo_Point2D.h>
 
 #include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_Constraint.h>
 #include <SketchPlugin_Point.h>
 
 #include <ModuleBase_IViewWindow.h>
@@ -108,6 +109,29 @@ void PartSet_WidgetSubShapeSelector::mouseMoved(ModuleBase_IViewWindow* theWindo
   }
 }
 
+//********************************************************************
+bool PartSet_WidgetSubShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
+{
+  bool aResult = ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
+
+  //if (aResult)
+  //GeomShapePtr aBaseShape = *anIt;
+  //           myCurrentSubShape->setShape(aBaseShape);
+  
+  FeaturePtr aFeature = feature();
+  AttributePoint2DPtr anAPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                                     aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
+  AttributePoint2DPtr aBPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                                     aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
+
+
+   //GeomDataAPI_Point2D anAPointAttr = aFeature->attribute(SketchPlugin_Constraint::ENTITY_A())
+  //data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), GeomDataAPI_Point2D::typeId());
+  //data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), GeomDataAPI_Point2D::typeId());
+
+  return aResult;
+}
+
 //********************************************************************
 void PartSet_WidgetSubShapeSelector::getHighlighted(
                            QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues)
index feee61b01ee6d6ad9670b05638214a1033d2a3dd..86ac40a9df59f551cabd5eb5b585f2b8591812ad 100644 (file)
@@ -67,6 +67,10 @@ Q_OBJECT
   /// \param theValues a list of presentations
   virtual void getHighlighted(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
 
+  /// Fills the attribute with the value of the selected owner
+  /// \param thePrs a selected owner
+  virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
+
 protected:
   /// Checks the widget validity. By default, it returns true.
   /// \param thePrs a selected presentation in the view
index 472cf8725db403ed1161abae8b02fc66f307a3ef..09f8dbcb6030459c7fdfccf8c25259259ecc7ccd 100755 (executable)
@@ -11,7 +11,7 @@
 //#include <GeomAPI_Lin2d.h>
 //#include <GeomAPI_Pnt2d.h>
 //#include <GeomAPI_XY.h>
-//#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point2D.h>
 //#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeReference.h>
 //#include <ModelAPI_AttributeRefList.h>
@@ -70,7 +70,9 @@ SketchPlugin_ConstraintSplit::SketchPlugin_ConstraintSplit()
 
 void SketchPlugin_ConstraintSplit::initAttributes()
 {
-  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeReference::typeId());
+  data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeReference::typeId());
+  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), GeomDataAPI_Point2D::typeId());
 
   //data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
   //data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttrList::typeId());
index d084b808375f564c73bc47ec8d369a4c946df5ce..e0888099058768fa4df4594adb55674370f7e784 100755 (executable)
@@ -16,8 +16,8 @@
  *  \brief Feature for creation of a new constraint filleting two objects which have coincident point
  *
  *  This constraint has three attributes:
- *  SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() for the filleting objects;
- *  SketchPlugin_Constraint::VALUE() contains radius of filleting circular arc
+ *  SketchPlugin_Constraint::VALUE() contains reference object to be splitted
+ *  SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() for the points of split;
  *
  *  Also the constraint has attribute SketchPlugin_Constraint::ENTITY_C()
  *  which contains created list objects forming the fillet
index ec8be9d1fc8dcfd5809e4443cf6e5df9c0e93db9..b8a79e1981b71b692964a9c672aa6f589da5e0ee 100644 (file)
       <!--  SketchConstraintSplit  -->
       <feature id="SketchConstraintSplit" title="Split" tooltip="Create constraints defining split of linear segment, arc or circle" icon="icons/Sketch/split.png">
         <sketch_sub_shape_selector
-            id="ConstraintEntityA"
+            id="ConstraintValue"
             label="Split feature"
             tooltip="Select feature for split"
             shape_types="edge"