]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
1. Tangent Arc - restart operation. Scenario: create Line, point, Start tangent arc...
authornds <nds@opencascade.com>
Wed, 7 Sep 2016 09:27:01 +0000 (12:27 +0300)
committernds <nds@opencascade.com>
Wed, 7 Sep 2016 09:27:18 +0000 (12:27 +0300)
2. #1717 split and length constraint

src/PartSet/PartSet_SketcherReetntrantMgr.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.h
src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp
src/SketchPlugin/SketchPlugin_ConstraintSplit.h
src/XGUI/XGUI_PropertyPanel.cpp

index 3f84648c87071f4ebbb409da957cb0232cc1fe6c..4cfcf167d8f49f9726c1ca2cb94d447d257c2013 100755 (executable)
@@ -34,6 +34,7 @@
 #include <XGUI_OperationMgr.h>
 #include <XGUI_PropertyPanel.h>
 #include <XGUI_ErrorMgr.h>
+#include <XGUI_SelectionMgr.h>
 
 #include <QToolButton>
 
@@ -157,6 +158,11 @@ bool PartSet_SketcherReetntrantMgr::processMouseMoved(ModuleBase_IViewWindow* th
       }
       bool aCanBeActivatedByMove = isLineFeature || isArcFeature;
       if (aCanBeActivatedByMove) {
+        /// before restarting of operation we need to clear selection, as it may take part in
+        /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
+        /// by mouse release when the operation was restarted.
+        workshop()->selector()->clearSelection();\r
+
         myPreviousFeature = aFOperation->feature();
         restartOperation();
         myPreviousFeature = FeaturePtr();
index ba18dae3e82b711fe03b25772d411ff0aaee6932..9a87f7f26c77d526ae4f33c9ad7a3663523476fb 100644 (file)
@@ -103,6 +103,18 @@ bool SketchPlugin_ConstraintLength::compute(const std::string& theAttributeId)
   return true;
 }
 
+bool SketchPlugin_ConstraintLength::computeLenghtValue(double& theValue)
+{
+  bool aResult = false;
+  std::shared_ptr<GeomAPI_Pnt> aPoint1, aPoint2;
+  std::shared_ptr<GeomDataAPI_Point2D> aStartPoint, anEndPoint;
+  if (getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint)) {
+    theValue = aPoint1->distance(aPoint2);
+    aResult = true;
+  }
+  return aResult;
+}
+
 bool SketchPlugin_ConstraintLength::getPoints(
   std::shared_ptr<GeomAPI_Pnt>& thePoint1, std::shared_ptr<GeomAPI_Pnt>& thePoint2,
   std::shared_ptr<GeomDataAPI_Point2D>& theStartPoint,
@@ -175,12 +187,9 @@ void SketchPlugin_ConstraintLength::attributeChanged(const std::string& theID) {
     std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
       ModelAPI_AttributeDouble>(attribute(SketchPlugin_Constraint::VALUE()));
     if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
-      std::shared_ptr<GeomAPI_Pnt> aPoint1, aPoint2;
-      std::shared_ptr<GeomDataAPI_Point2D> aStartPoint, anEndPoint;
-      if (getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint)) {
-        double aLength = aPoint1->distance(aPoint2);
+      double aLength;
+      if (computeLenghtValue(aLength))
         aValueAttr->setValue(aLength);
-      }
     }
   } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) {
     myFlyoutUpdate = true;
index 662e276ee0bf265fd7af21e00a70fda1b1c2f24e..af63c7f9d785ba8bcfe8bf8f8b1b0040e54fa4f3 100644 (file)
@@ -71,8 +71,13 @@ class SketchPlugin_ConstraintLength : public SketchPlugin_ConstraintBase
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintLength();
 
+  /// Computes distance between lenght point attributes
+  /// \param theValue [out] distance or 0 if one of point attributes is not initialized
+  /// \return boolean value if distance is computed
+  bool computeLenghtValue(double& theValue);
+
 private:
-  // retrns the points-base of length, returns false if it is not possible
+  /// retrns the points-base of length, returns false if it is not possible
   bool getPoints(
     std::shared_ptr<GeomAPI_Pnt>& thePoint1, std::shared_ptr<GeomAPI_Pnt>& thePoint2,
     std::shared_ptr<GeomDataAPI_Point2D>& theStartPoint,
index 7ef3dd5531c3ff9fddc771fcfb66bab0c291de8f..54edf285c6221d9270b2a60f7d398cee68d5b629 100755 (executable)
@@ -17,6 +17,7 @@
 
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_AttributeDouble.h>
 
 #include <SketchPlugin_Line.h>
 #include <SketchPlugin_Arc.h>
@@ -25,6 +26,7 @@
 #include <SketchPlugin_ConstraintEqual.h>
 #include <SketchPlugin_ConstraintParallel.h>
 #include <SketchPlugin_ConstraintTangent.h>
+#include <SketchPlugin_ConstraintLength.h>
 #include <SketchPlugin_ConstraintMirror.h>
 #include <SketchPlugin_MultiRotation.h>
 #include <SketchPlugin_MultiTranslation.h>
@@ -86,12 +88,10 @@ void SketchPlugin_ConstraintSplit::execute()
   // Find feature constraints
   FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
   ResultPtr aBaseFeatureResult = getFeatureResult(aBaseFeature);
-
-  std::set<FeaturePtr> aFeaturesToDelete;
+  std::set<FeaturePtr> aFeaturesToDelete, aFeaturesToUpdate;
   std::map<FeaturePtr, IdToPointPair> aTangentFeatures;
   std::map<FeaturePtr, IdToPointPair> aCoincidenceToFeature;
-  //std::map<FeaturePtr, IdToPointPair> aCoincidenceToPoint;
-  getConstraints(aFeaturesToDelete, aTangentFeatures, aCoincidenceToFeature);//, aCoincidenceToPoint);
+  getConstraints(aFeaturesToDelete, aFeaturesToUpdate, aTangentFeatures, aCoincidenceToFeature);
 
   std::map<AttributePtr, std::list<AttributePtr> > aBaseRefAttributes;
   getRefAttributes(aBaseFeature, aBaseRefAttributes);
@@ -145,21 +145,6 @@ void SketchPlugin_ConstraintSplit::execute()
     }
   }
 
-  /*if (!aCoincidenceToPoint.empty()) {
-    std::cout << std::endl;
-    std::cout << "Coincidences to points on base feature[" << aCoincidenceToPoint.size() << "]: " << std::endl;
-    std::map<FeaturePtr, IdToPointPair>::const_iterator anIt = aCoincidenceToPoint.begin(),
-                                                        aLast = aCoincidenceToPoint.end();
-    for (int i = 1; anIt != aLast; anIt++, i++) {
-      FeaturePtr aFeature = (*anIt).first;
-      std::string anAttributeId = (*anIt).second.first;
-      std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = (*anIt).second.second;
-
-      std::cout << i << "-" << getFeatureInfo(aFeature) << std::endl;
-      std::cout <<     " -Attribute to correct:" << anAttributeId << std::endl;
-      std::cout <<     " -Point attribute:" << ModelGeomAlgo_Point2D::getPointAttributeInfo(aPointAttr) << std::endl;
-    }
-  }*/
   std::map<AttributePtr, std::list<AttributePtr> >::const_iterator aRefIt = aBaseRefAttributes.begin(),
                                                                    aRefLast = aBaseRefAttributes.end();
   std::cout << std::endl << "References to attributes of base feature [" << aBaseRefAttributes.size() << "]" << std::endl;
@@ -262,9 +247,6 @@ void SketchPlugin_ConstraintSplit::execute()
   // coincidence to feature
   updateCoincidenceConstraintsToFeature(aCoincidenceToFeature, aFurtherCoincidences,
                                         aFeatureResults);
-  // coincidence to points
-  //updateCoincidenceConstraintsToFeature(aCoincidenceToPoint, aFurtherCoincidences,
-  //                                      std::set<ResultPtr>());
   // tangency
   updateTangentConstraintsToFeature(aTangentFeatures, aFurtherCoincidences);
 
@@ -282,6 +264,17 @@ void SketchPlugin_ConstraintSplit::execute()
 #endif
   ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToDelete);
 
+#ifdef DEBUG_SPLIT
+  std::cout << "update features after split:" << std::endl;
+  std::set<FeaturePtr>::const_iterator anUIt = aFeaturesToUpdate.begin(),
+                                       anULast = aFeaturesToUpdate.end();
+  for (; anUIt != anULast; anUIt++) {
+    std::cout << getFeatureInfo(*anUIt, false) << std::endl;
+    std::cout << std::endl;
+  }
+#endif
+  updateFeaturesAfterSplit(aFeaturesToUpdate);
+
   // Send events to update the sub-features by the solver.
   if(isUpdateFlushed) {
     Events_Loop::loop()->setFlushed(anUpdateEvent, true);
@@ -344,9 +337,9 @@ void SketchPlugin_ConstraintSplit::getFeaturePoints(AttributePoint2DPtr& theStar
 }
 
 void SketchPlugin_ConstraintSplit::getConstraints(std::set<FeaturePtr>& theFeaturesToDelete,
+                                      std::set<FeaturePtr>& theFeaturesToUpdate,
                                       std::map<FeaturePtr, IdToPointPair>& theTangentFeatures,
-                                      std::map<FeaturePtr, IdToPointPair>& theCoincidenceToFeature/*,
-                                      std::map<FeaturePtr, IdToPointPair>& theCoincidenceToPoint*/)
+                                      std::map<FeaturePtr, IdToPointPair>& theCoincidenceToFeature)
 {
   std::shared_ptr<ModelAPI_Data> aData = data();
 
@@ -369,6 +362,8 @@ void SketchPlugin_ConstraintSplit::getConstraints(std::set<FeaturePtr>& theFeatu
         aRefFeatureKind == SketchPlugin_MultiRotation::ID() ||
         aRefFeatureKind == SketchPlugin_MultiTranslation::ID())
       theFeaturesToDelete.insert(aRefFeature);
+    else if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID())
+      theFeaturesToUpdate.insert(aRefFeature);
     else if (aRefFeatureKind == SketchPlugin_ConstraintTangent::ID()) {
       if (aBaseFeature->getKind() == SketchPlugin_Circle::ID()) /// TEMPORARY limitaion
         theFeaturesToDelete.insert(aRefFeature); /// until tangency between arc and line is implemented
@@ -456,9 +451,6 @@ void SketchPlugin_ConstraintSplit::getConstraints(std::set<FeaturePtr>& theFeatu
         if (isToFeature)
           theCoincidenceToFeature[aRefFeature] = std::make_pair(anAttributeToBeModified,
                                                                 aCoincidentPoint);
-        //else
-          //theCoincidenceToPoint[aRefFeature] = std::make_pair(anAttributeToBeModified,
-          //                                                    aCoincidentPoint);
       }
       else
         theFeaturesToDelete.insert(aRefFeature); /// this case should not happen
@@ -1103,6 +1095,28 @@ FeaturePtr SketchPlugin_ConstraintSplit::createConstraintForObjects(const std::s
   return aConstraint;
 }
 
+void SketchPlugin_ConstraintSplit::updateFeaturesAfterSplit(
+                                                   const std::set<FeaturePtr>& theFeaturesToUpdate)
+{
+  std::set<FeaturePtr>::const_iterator anIt = theFeaturesToUpdate.begin(),
+                                       aLast = theFeaturesToUpdate.end();
+  for (; anIt != aLast; anIt++) {
+    FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
+    std::string aRefFeatureKind = aRefFeature->getKind();
+    if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID()) {
+      std::shared_ptr<SketchPlugin_ConstraintLength> aLenghtFeature =
+                              std::dynamic_pointer_cast<SketchPlugin_ConstraintLength>(*anIt);
+      if (aLenghtFeature.get()) {
+        std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+            ModelAPI_AttributeDouble>(aLenghtFeature->attribute(SketchPlugin_Constraint::VALUE()));
+        double aValue;
+        if (aLenghtFeature->computeLenghtValue(aValue) && aValueAttr.get())
+          aValueAttr->setValue(aValue);
+      }
+    }
+  }
+}
+
 std::shared_ptr<ModelAPI_Result> SketchPlugin_ConstraintSplit::getFeatureResult(
                                     const std::shared_ptr<ModelAPI_Feature>& theFeature)
 {
index f8f90dcb7e3eb962ef16d44b15bcb3cbd586622d..1acbadd2b8751257412e7c78626df2663f4f4c69 100755 (executable)
@@ -101,10 +101,12 @@ private:
   /// Obtains those constraints of the feature that should be modified. output maps contain
   /// point of coincidence and attribute id to be modified after split
   /// \param theFeaturesToDelete [out] constrains that will be deleted after split
+  /// \param theFeaturesToUpdate [out] constrains that will be updated after split
   /// \param theTangentFeatures  [out] tangent feature to be connected to new feature
   /// \param theCoincidenceToFeature [out] coincidence to feature to be connected to new feature
   /// \param theCoincidenceToPoint [out] coincidence to point be connected to new feature
   void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
+              std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToUpdate,
               std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theTangentFeatures,
               std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature/*,
               std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToPoint*/);
@@ -240,6 +242,10 @@ private:
                         const std::shared_ptr<ModelAPI_Object>& theFirstObject,
                         const std::shared_ptr<ModelAPI_Object>& theSecondObject);
 
+  /// Add feature coincidence constraint between given attributes
+  /// \param theFeaturesToUpdate a constraint index
+  void updateFeaturesAfterSplit(const std::set<FeaturePtr>& theFeaturesToUpdate);
+
   /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
   /// \param theFeature a feature
   /// \return result object
index e37d69f9132f077dba252ba81d4d94f5ecd2c3f4..82c99cf8c64aaaaeb078ba64a5a2275343fae90b 100755 (executable)
@@ -241,7 +241,7 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget,
     if (isFoundWidget || !theWidget) {
 
       if (!aValidators->isCase(aCurrentWidget->feature(), aCurrentWidget->attributeID()))
-        continue; // this attribute is not participated in the current case
+        continue; // this attribute does not participate in the current case
       if (isCheckVisibility && !aCurrentWidget->isInternal()) {
         if (!aCurrentWidget->isVisible())
           continue;