Salome HOME
Merge branch 'master' of newgeom:newgeom.git
authorsbh <sergey.belash@opencascade.com>
Mon, 10 Nov 2014 11:53:08 +0000 (14:53 +0300)
committersbh <sergey.belash@opencascade.com>
Mon, 10 Nov 2014 11:53:08 +0000 (14:53 +0300)
src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp
src/Model/Model_Update.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp

index e582019b4839f3d18ee494cd9ff39c0f60860873..de5cdbf2204eaf94ad0be7e3a4c87ac07dbcaa36 100644 (file)
@@ -83,6 +83,13 @@ void FeaturesPlugin_Boolean::execute()
     Events_Error::send(aFeatureError, this);
     return;
   }  
+  // if result of Boolean operation is same as was before it means that Boolean operation has no sence
+  // and naming provides no result, so, generate an error in this case
+  if (anObject->isEqual(aFeature->shape())) {
+    std::string aFeatureError = "Boolean feature: operation was not performed";  
+    Events_Error::send(aFeatureError, this);
+    return;
+  }
   //LoadNamingDS
   LoadNamingDS(aFeature, aResultBody, anObject, aTool, aType);
 
index 4c23c9c30f451d5eac89fb60e20ec27cd7aad041..cb511c8e3773c1c75ca25310bc84f2ac6e60fdf4 100644 (file)
@@ -179,12 +179,6 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
         if (updateFeature(aComposite->subFeature(a)))
           aMustbeUpdated = true;
       }
-      if (aMustbeUpdated) {
-        for(int a = 0; a < aSubsNum; a++) {
-          if (aComposite->subFeature(a) && aFactory->validate(aComposite->subFeature(a)))
-            aComposite->subFeature(a)->execute();
-        }
-      }
     }
     // check all references: if referenced objects are updated, this object also must be updated
     std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
@@ -201,6 +195,7 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
       }
     }
 
+    //std::cout<<"Update feature "<<theFeature->getKind()<<" must be updated = "<<aMustbeUpdated<<std::endl;
     // execute feature if it must be updated
     if (aMustbeUpdated) {
       if (boost::dynamic_pointer_cast<Model_Document>(theFeature->document())->executeFeatures() ||
@@ -209,6 +204,7 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
           if (isAutomatic || (myJustCreatedOrUpdated.find(theFeature) != myJustCreatedOrUpdated.end()) ||
             !theFeature->isPersistentResult() /* execute quick, not persistent results */) 
           {
+            //std::cout<<"Execute feature "<<theFeature->getKind()<<std::endl;
             // before execution update the selection attributes if any
             list<AttributePtr> aRefs = 
               theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
@@ -226,6 +222,26 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
                   aSel->value(a)->update();
               }
             }
+            // for sketch after update of plane (by update of selection attribute)
+            // but before execute, all sub-elements also must be updated (due to the plane changes)
+            if (aComposite) {
+              int aSubsNum = aComposite->numberOfSubs();
+              for(int a = 0; a < aSubsNum; a++) {
+                FeaturePtr aSub = aComposite->subFeature(a);
+                bool aWasModified = myUpdated[aSub];
+                myUpdated.erase(myUpdated.find(aSub)); // erase to update for sure (plane may be changed)
+                myInitial.insert(aSub);
+                updateFeature(aSub);
+                myUpdated[aSub] = aWasModified; // restore value
+              }
+              // re-execute after update: solver may update the previous values, so, shapes must be
+              // updated
+              for(int a = 0; a < aSubsNum; a++) {
+                if (aComposite->subFeature(a) && aFactory->validate(aComposite->subFeature(a)))
+                  aComposite->subFeature(a)->execute();
+              }
+            }
+
             // execute in try-catch to avoid internal problems of the feature
             try {
               theFeature->execute();
index d1369536111582223c3d8a32afcfb399a680a85d..364d7c9d20e1b0985cd195a0d0ae2f46c89a6d15 100644 (file)
@@ -152,13 +152,25 @@ ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView
                                         FeaturePtr theSketch,
                                         const QList<ModuleBase_ViewerPrs>& theSelected,
                                         const QList<ModuleBase_ViewerPrs>& theHighlighted)
+{
+  // firstly it finds the feature in the list of highlight
+  ObjectPtr aDeltaObject  = nearestFeature(thePoint, theView, theSketch, theHighlighted);
+  if (!aDeltaObject)
+    // secondly it finds the feature in the list of selected objects
+    aDeltaObject  = nearestFeature(thePoint, theView, theSketch, theSelected);
+
+  return aDeltaObject;
+}
+
+ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
+                                        FeaturePtr theSketch,
+                                        const QList<ModuleBase_ViewerPrs>& thePresentations)
 {
   ObjectPtr aDeltaObject;
-  // 1. find the object in the highlighted list
-  if (theHighlighted.size() > 0) {
-    aDeltaObject = theHighlighted.first().object();
-  }
-  // 2. find it in the selected list by the selected point
+
+  CompositeFeaturePtr aSketch = 
+      boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theSketch);
+  // 1. find it in the selected list by the selected point
   if (!aDeltaObject) {
     double aX, anY;
     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView);
@@ -167,13 +179,13 @@ ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView
     FeaturePtr aFeature;
     double aMinDelta = -1;
     ModuleBase_ViewerPrs aPrs;
-    foreach (ModuleBase_ViewerPrs aPrs, theSelected) {
+    foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
       if (!aPrs.object())
         continue;
       FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
       boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
           SketchPlugin_Feature>(aFeature);
-      if (!aSketchFeature)
+      if (!aSketchFeature || !aSketch->isSub(aSketchFeature))
         continue;
 
       double aDelta = aSketchFeature->distanceToPoint(
@@ -184,10 +196,17 @@ ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView
       }
     }
   }
-  // 3. if the object is not found, returns the first selected one
-  if (!aDeltaObject && theSelected.size() > 0)
-    aDeltaObject = theSelected.first().object();
-
+  // 2. if the object is not found, returns the first selected sketch feature
+  if (!aDeltaObject && thePresentations.size() > 0) {
+    // there can be some highlighted objects, e.g. a result of boolean operation and a sketch point
+    foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
+      if (!aPrs.object())
+        continue;
+      FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
+      if (aFeature && aSketch->isSub(aFeature))
+        aDeltaObject = aPrs.object();
+    }
+  }
   return aDeltaObject;
 }
 
index 912db7307b5b9de3be76a4e3ca7b53b629193fb4..30838ae09f66fc9869e36d6e48c87a3d5a7421e0 100644 (file)
@@ -160,6 +160,18 @@ class PARTSET_EXPORT PartSet_Tools
   /// \param theY the output vertical coordinate of the point
   static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
                              Handle_V3d_View theView, double& theX, double& theY);
+protected:
+  /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
+  /// if it exists, the first object is returned. Secondly, there is an iteration on
+  /// the selected list to find the point. Thirdly, if the object is not found under the
+  /// the point, the first selected object is returned.
+  /// \param thePoint a screen point
+  /// \param theView a 3D view
+  /// \param theSketch the sketch feature
+  /// \param thePresentations the list of presentations
+  static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
+                                  const QList<ModuleBase_ViewerPrs>& thePresentations);
+
 };
 
 #endif
index 3669232cba85ab5d0829c37752865116a8e1e57d..a65a6b7c6ccef3c98d1bc7a6a183b663f59625ad 100644 (file)
@@ -45,6 +45,7 @@ void SketchPlugin_Circle::execute()
       boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(RADIUS_ID()));
     if (aCenterAttr->isInitialized() && aRadiusAttr->isInitialized()) {
       boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+      //std::cout<<"Execute circle "<<aCenter->x()<<" "<<aCenter->y()<<" "<<aCenter->z()<<std::endl;
       // make a visible point
       boost::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
       boost::shared_ptr<ModelAPI_ResultConstruction> aConstr1 = document()->createConstruction(
index 22a4668158244b4d72ae5c7f2138883b02ea4353..501478a32d77ffb80452128daa62cf759bf9fa14 100644 (file)
@@ -44,6 +44,8 @@ void SketchPlugin_Line::execute()
     if (aStartAttr->isInitialized() && anEndAttr->isInitialized()) {
       boost::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
       boost::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
+      //std::cout<<"Execute line "<<aStart->x()<<" "<<aStart->y()<<" "<<aStart->z()<<" - "
+      //  <<anEnd->x()<<" "<<anEnd->y()<<" "<<anEnd->z()<<std::endl;
       // make linear edge
       boost::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
       // store the result
index 813ce28fb3bc5a0a8bce780917d4895cb97eab26..e1ac62b0c8c03519117e1aa950f11469dff472d9 100644 (file)
@@ -314,6 +314,7 @@ void SketchPlugin_Sketch::attributeChanged() {
       boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
 
       if (kIsAttrChanged) {
+        /* now it is in updater
         // the plane was changed, so reexecute sub-elements to update shapes (located in new plane)
         ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
         list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
@@ -324,6 +325,7 @@ void SketchPlugin_Sketch::attributeChanged() {
             aFeature->execute();
           }
         }
+        */
         kIsAttrChanged = false;
       }
     }