Salome HOME
BUG: Sketch plane is initialized by click in empty place
authornds <nds@opencascade.com>
Thu, 14 Jan 2016 13:40:48 +0000 (16:40 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:03:03 +0000 (17:03 +0300)
Scenario:
Start sketch
Move mouse over planes(one of them is highlighted)
Click in empty place
Result: sketch nested actions are enabled, sketch planes stayed in the viewer.

src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/ModuleBase/ModuleBase_WidgetValidated.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h
src/SketchPlugin/SketchPlugin_Plugin.cpp

index 6fa8eae78e5db813aebb9ae109790c2c3058f0b1..09071536151acd0d81ed841f1faac1229287fc22 100755 (executable)
@@ -359,7 +359,7 @@ bool ModuleBase_WidgetMultiSelector::processDelete()
     myWorkshop->setSelected(getAttributeSelection());
     myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeAllObjects, true);
   }
-  return true; // if the delete should be processed outsize, the method should return isDone
+  return aDone;
 }
 
 //********************************************************************
index 55abdb5035e40020379be97f8b0697d81c85d337..0dab2cee1fe64a4a32a37fdcddaa1f5c4944d361 100644 (file)
@@ -136,17 +136,10 @@ bool ModuleBase_WidgetValidated::isValidSelection(const ModuleBase_ViewerPrs& th
     return aValid;
   }
 
-  DataPtr aData = myFeature->data();
-  AttributePtr anAttribute = myFeature->attribute(attributeID());
-
   // stores the current values of the widget attribute
-  Events_Loop* aLoop = Events_Loop::loop();
-  // blocks the flush signals to avoid the temporary objects visualization in the viewer
-  // they should not be shown in order to do not lose highlight by erasing them
-  bool isActive = aLoop->activateFlushes(false);
+  bool isFlushesActived, isAttributeSetInitializedBlocked;
+  blockAttribute(true, isFlushesActived, isAttributeSetInitializedBlocked);
 
-  aData->blockSendAttributeUpdated(true);
-  bool isAttributeBlocked = anAttribute->blockSetInitialized(true);
   storeAttributeValue();
 
   // saves the owner value to the widget attribute
@@ -157,10 +150,8 @@ bool ModuleBase_WidgetValidated::isValidSelection(const ModuleBase_ViewerPrs& th
 
   // restores the current values of the widget attribute
   restoreAttributeValue(aValid);
-  aData->blockSendAttributeUpdated(false);
-  anAttribute->blockSetInitialized(isAttributeBlocked);
-  aLoop->activateFlushes(isActive);
 
+  blockAttribute(false, isFlushesActived, isAttributeSetInitializedBlocked);
   // In particular case the results are deleted and called as redisplayed inside of this
   // highlight-selection, to they must be flushed as soon as possible.
   // Example: selection of group-vertices subshapes with shift pressend on body. Without
@@ -168,8 +159,8 @@ bool ModuleBase_WidgetValidated::isValidSelection(const ModuleBase_ViewerPrs& th
   //  removed results still in the viewer.
   static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
   static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  aLoop->flush(aDeletedEvent);
-  aLoop->flush(aRedispEvent);
+  Events_Loop::loop()->flush(aDeletedEvent);
+  Events_Loop::loop()->flush(aRedispEvent);
 
   storeValidState(theValue, aValid);
   return aValid;
@@ -214,6 +205,28 @@ void ModuleBase_WidgetValidated::activateFilters(const bool toActivate)
   }
 }
 
+//********************************************************************
+void ModuleBase_WidgetValidated::blockAttribute(const bool& theToBlock, bool& isFlushesActived,
+                                                bool& isAttributeSetInitializedBlocked)
+{
+  Events_Loop* aLoop = Events_Loop::loop();
+  DataPtr aData = myFeature->data();
+  AttributePtr anAttribute = myFeature->attribute(attributeID());
+  if (theToBlock) {
+    // blocks the flush signals to avoid the temporary objects visualization in the viewer
+    // they should not be shown in order to do not lose highlight by erasing them
+    isFlushesActived = aLoop->activateFlushes(false);
+
+    aData->blockSendAttributeUpdated(true);
+    isAttributeSetInitializedBlocked = anAttribute->blockSetInitialized(true);
+  }
+  else {
+    aData->blockSendAttributeUpdated(false);
+    anAttribute->blockSetInitialized(isAttributeSetInitializedBlocked);
+    aLoop->activateFlushes(isFlushesActived);
+  }
+}
+
 //********************************************************************
 void ModuleBase_WidgetValidated::storeValidState(const ModuleBase_ViewerPrs& theValue, const bool theValid)
 {
index 385f11a00f04e334e29fd048ebad38dc6765ae0e..60ed4edc9551367d7f288f28bee1d8808046e04b 100644 (file)
@@ -123,6 +123,15 @@ protected:
   /// \param toActivate a flag about activation or deactivation the filters
   void activateFilters(const bool toActivate);
 
+  /// Block the model flush of update and intialization of attribute
+  /// \param theToBlock flag whether the model is blocked or unblocked
+  /// \param isActive out value if model is blocked, in value if model is unblocked
+  /// to be used to restore flush state when unblocked
+  /// \param isAttributeSetInitializedBlocked out value if model is blocked
+  /// in value if model is unblocked to be used to restore previous state when unblocked
+  virtual void blockAttribute(const bool& theToBlock, bool& isFlushesActived,
+                              bool& isAttributeSetInitializedBlocked);
+
 protected:
   /// Reference to workshop
   ModuleBase_IWorkshop* myWorkshop; 
index d64f10952c46dc8c4f8dd29cfc8d0d2b19369098..b8c78602c9726a482baac5d078488197c274f0e8 100644 (file)
@@ -185,6 +185,27 @@ void PartSet_WidgetSketchLabel::onShowConstraint(bool theOn)
     emit showConstraintToggled(theOn, aState);
 }
 
+void PartSet_WidgetSketchLabel::blockAttribute(const bool& theToBlock, bool& isFlushesActived,
+                                               bool& isAttributeSetInitializedBlocked)
+{
+  ModuleBase_WidgetValidated::blockAttribute(theToBlock, isFlushesActived,
+                                             isAttributeSetInitializedBlocked);
+  // We do not restore the previous state of isAttributeSetInitializedBlocked for each of
+  // attributes. It it is necessary, these states should be append to the method attributes
+  // or stored in the widget
+
+  std::list<AttributePtr> anAttributes = myFeature->data()->attributes("");
+  std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
+  QStringList aValues;
+  for(; anIt != aLast; anIt++) {
+    AttributePtr anAttribute = *anIt;
+    if (theToBlock)
+      anAttribute->blockSetInitialized(true);
+    else
+      anAttribute->blockSetInitialized(isAttributeSetInitializedBlocked);
+  }
+}
+
 void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs)
 {
   // 1. hide main planes if they have been displayed
index 9d909225380c49293367ecce7f25c539455ef701..600147ed4c87cada0beb8376c5b2fb9133c8de58 100644 (file)
@@ -121,6 +121,17 @@ protected:
   /// The methiod called when widget is activated
   virtual void activateCustom();
 
+  /// Block the model flush of update and intialization of attribute
+  /// In additional to curstom realization it blocks initialization for all feature attributes
+  /// as the current attribute is selection but its modification leads to other attributes change
+  /// \param theToBlock flag whether the model is blocked or unblocked
+  /// \param isActive out value if model is blocked, in value if model is unblocked
+  /// to be used to restore flush state when unblocked
+  /// \param isAttributeSetInitializedBlocked out value if model is blocked
+  /// in value if model is unblocked to be used to restore previous state when unblocked
+  virtual void blockAttribute(const bool& theToBlock, bool& isFlushesActived,
+                              bool& isAttributeSetInitializedBlocked);
+
   /// Erase preview planes, disconnect widget, change the view projection
   /// \param thePrs a selected presentation
   void updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs);
index a40e7772252eb6b964b55ac651ba5626de49487f..06a3d570257e14ff0a9163602e8e8331d2219db5 100644 (file)
@@ -174,7 +174,10 @@ std::shared_ptr<ModelAPI_FeatureStateMessage> SketchPlugin_Plugin
     if (aData) {
       std::shared_ptr<GeomDataAPI_Dir> aNormal =
         std::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
-      aHasSketchPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
+      // it is important to check whether the normal attribute is initialized
+      // because it is possible that normal values are filled when the plane is checked on validity
+      aHasSketchPlane = aNormal && aNormal->isInitialized() &&
+                        !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
 
       aMsg->setState(SketchPlugin_Point::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_Line::ID(), aHasSketchPlane);