]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge remote-tracking branch 'remotes/origin/SolveSpace'
authorazv <azv@opencascade.com>
Mon, 26 May 2014 07:03:18 +0000 (11:03 +0400)
committerazv <azv@opencascade.com>
Mon, 26 May 2014 07:03:18 +0000 (11:03 +0400)
14 files changed:
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp
src/Model/Model_Data.cpp
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_Object.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/PartSetPlugin/plugin-PartSet.xml
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_Workshop.cpp

index 84e4234bde052e0e76ef1c92aa6eba8c79306ee2..2cc821e39fc26a8d52a3103a0fa3adf923b379ed 100644 (file)
@@ -18,6 +18,8 @@ boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::line(
 
   if (aStart.IsEqual(anEnd, Precision::Confusion()))
     return boost::shared_ptr<GeomAPI_Shape>();
+  if (Abs(aStart.SquareDistance(anEnd)) > 1.e+100)
+    return boost::shared_ptr<GeomAPI_Shape>();
   BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
   boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
   TopoDS_Edge anEdge = anEdgeBuilder.Edge();
index 03effc8e3c9058cfb99083ea373862931075cde2..f794bda07c143f0936ff573d656542285969b459 100644 (file)
@@ -36,10 +36,21 @@ string Model_Data::getName()
 
 void Model_Data::setName(string theName)
 {
-  TDataStd_Name::Set(myLab, theName.c_str());
-  static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
-  Model_FeatureUpdatedMessage aMsg(myFeature, anEvent);
-  Events_Loop::loop()->send(aMsg, false);
+  bool isModified = false;
+  Handle(TDataStd_Name) aName;
+  if (!myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
+    TDataStd_Name::Set(myLab, theName.c_str());
+    isModified = true;
+  } else {
+    isModified = !aName->Get().IsEqual(theName.c_str());
+    if (isModified)
+      aName->Set(theName.c_str());
+  }
+  if (isModified) {
+    static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+    Model_FeatureUpdatedMessage aMsg(myFeature, anEvent);
+    Events_Loop::loop()->send(aMsg, false);
+  }
 }
 
 void Model_Data::addAttribute(string theID, string theAttrType)
index 6343d8b7b7d837fd35d5348701a136bcc9429089..2c29b653558c48e7dfbaa1499eff5cfeed25aee4 100644 (file)
@@ -232,7 +232,7 @@ void Model_Document::abortOperation()
   if (myNestedNum == 0)
     myNestedNum = -1;
   myDoc->AbortCommand();
-  synchronizeFeatures();
+  synchronizeFeatures(true);
   // abort for all subs
   set<string>::iterator aSubIter = mySubs.begin();
   for(; aSubIter != mySubs.end(); aSubIter++)
@@ -269,7 +269,7 @@ void Model_Document::undo()
   if (myNestedNum > 0) myNestedNum--;
   if (!myIsEmptyTr[myTransactionsAfterSave])
     myDoc->Undo();
-  synchronizeFeatures();
+  synchronizeFeatures(true);
   // undo for all subs
   set<string>::iterator aSubIter = mySubs.begin();
   for(; aSubIter != mySubs.end(); aSubIter++)
@@ -294,7 +294,7 @@ void Model_Document::redo()
   if (!myIsEmptyTr[myTransactionsAfterSave])
     myDoc->Redo();
   myTransactionsAfterSave++;
-  synchronizeFeatures();
+  synchronizeFeatures(true);
   // redo for all subs
   set<string>::iterator aSubIter = mySubs.begin();
   for(; aSubIter != mySubs.end(); aSubIter++)
@@ -566,7 +566,7 @@ boost::shared_ptr<ModelAPI_Feature> Model_Document::objectByFeature(
   return boost::shared_ptr<ModelAPI_Feature>(); // not found
 }
 
-void Model_Document::synchronizeFeatures()
+void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
 {
   boost::shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
   // update features
@@ -585,11 +585,14 @@ void Model_Document::synchronizeFeatures()
       aDSTag = aFLabIter.Value()->Label().Tag();
     }
     if (aDSTag > aFeatureTag) { // feature is removed
-      Model_FeatureDeletedMessage aMsg1(aThis, FEATURES_GROUP);
-      Model_FeatureDeletedMessage aMsg2(aThis, (*aFIter)->getGroup());
+      FeaturePtr aFeature = *aFIter;
       aFIter = myFeatures.erase(aFIter);
       // event: model is updated
-      Events_Loop::loop()->send(aMsg1);
+      if (aFeature->isInHistory()) {
+        Model_FeatureDeletedMessage aMsg1(aThis, FEATURES_GROUP);
+        Events_Loop::loop()->send(aMsg1);
+      }
+      Model_FeatureDeletedMessage aMsg2(aThis, aFeature->getGroup());
       Events_Loop::loop()->send(aMsg2);
     } else if (aDSTag < aFeatureTag) { // a new feature is inserted
       // create a feature
@@ -625,6 +628,11 @@ void Model_Document::synchronizeFeatures()
       // feature for this label is added, so go to the next label
       aFLabIter.Next();
     } else { // nothing is changed, both iterators are incremented
+      if (theMarkUpdated) {
+        static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+        Model_FeatureUpdatedMessage aMsg(*aFIter, anEvent);
+        Events_Loop::loop()->send(aMsg);
+      }
       aFIter++;
       aFLabIter.Next();
     }
@@ -633,6 +641,8 @@ void Model_Document::synchronizeFeatures()
   boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->
     setCheckTransactions(false);
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_CREATED));
+  if (theMarkUpdated)
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_DELETED));
   boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->
     setCheckTransactions(true);
index d8fee7e01f5a1978090b0ea29c250512ab8cfd16..097a3ba249446156189b5474494422f6a3ad679a 100644 (file)
@@ -103,7 +103,7 @@ protected:
     const boost::shared_ptr<ModelAPI_Feature> theFeature);
 
   //! Synchronizes myFeatures list with the updated document
-  void synchronizeFeatures();
+  void synchronizeFeatures(const bool theMarkUpdated = false);
 
   //! Creates new document with binary file format
   Model_Document(const std::string theID);
index 8179d701d6d70c7032fdad2deba769ae3d72db08..811edf709171f691d7f0340747d471d1011bea10 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <Model.h>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_Document.h>
 
 #include <TDataStd_Name.hxx>
 
@@ -34,7 +35,7 @@ public:
   MODEL_EXPORT virtual const std::string& getKind() {return myRef->getKind();}
 
   /// Returns to which group in the document must be added feature
-  MODEL_EXPORT virtual const std::string& getGroup() {return myRef->getGroup();}
+  MODEL_EXPORT virtual const std::string& getGroup() {return FEATURES_GROUP;}
 
   /// Returns document this feature belongs to
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> document()
index 63f7a1a373a1aa1ada079af3a030afb43eb502fc..57fbe728fbcd98bb670e2d181d28cd22ff4794e1 100644 (file)
@@ -17,6 +17,7 @@
 #include <XGUI_ViewPort.h>
 #include <XGUI_ActionsMgr.h>
 #include <XGUI_ViewerProxy.h>
+#include <XGUI_ContextMenuMgr.h>
 
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
@@ -54,6 +55,10 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
   connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
 
+  XGUI_ContextMenuMgr* aContextMenuMgr = myWorkshop->contextMenuMgr();
+  connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), 
+          this, SLOT(onContextMenuCommand(const QString&, bool)));
+
   connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)),
           this, SLOT(onMousePressed(QMouseEvent*)));
   connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)),
@@ -193,8 +198,8 @@ void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr<Mo
     std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted(TopAbs_VERTEX);
     aPreviewOp->init(theFeature, aSelected, aHighlighted);
   }
-  myWorkshop->actionsMgr()->updateCheckState();
   sendOperation(anOperation);
+  myWorkshop->actionsMgr()->updateCheckState();
 }
 
 void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
@@ -407,11 +412,11 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
 
 void PartSet_Module::editFeature(FeaturePtr theFeature)
 {
-  /*if (!theFeature)
+  if (!theFeature)
     return;
 
   if (theFeature->getKind() == "Sketch") {
     onLaunchOperation(theFeature->getKind(), theFeature);
-    visualizePreview(theFeature, true);
-  }*/
+    updateCurrentPreview(theFeature->getKind());
+  }
 }
index eb65c3659515f3b4d05274a1e9121905a8916345..f50dcb41df200e73602dd1eac89418db885328f6 100644 (file)
@@ -52,7 +52,8 @@ std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<Mode
 }
 
 void PartSet_OperationSketch::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                                   const std::list<XGUI_ViewerPrs>& thePresentations)
+                                   const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+                                   const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
 {
   setFeature(theFeature);
 }
@@ -141,20 +142,21 @@ bool PartSet_OperationSketch::isNestedOperationsEnabled() const
   return hasSketchPlane();
 }
 
+void PartSet_OperationSketch::startOperation()
+{
+  if (!feature())
+    setFeature(createFeature());
+}
+
 bool PartSet_OperationSketch::hasSketchPlane() const
 {
   bool aHasPlane = false;
 
   if (feature()) {
-    // set plane parameters to feature
     boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-
     boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
-    // temporary solution for main planes only
     boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
       boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
-    double aX = aNormal->x(), anY = aNormal->y(), aZ = aNormal->z();
-
     aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
   }
   return aHasPlane;
index 8f3a8fd4e856a4b898641137c8497159a50129de..d40a55331a198a5fdccbb4fdb9cbc8a22872ffda 100644 (file)
@@ -35,10 +35,11 @@ public:
   virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
 
   /// Initializes some fields accorging to the feature
-  /// \param theFeature the feature
-  /// \param thePresentations the list of additional presentations
+  /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                    const std::list<XGUI_ViewerPrs>& thePresentations);
+                    const std::list<XGUI_ViewerPrs>& theSelected,
+                    const std::list<XGUI_ViewerPrs>& theHighlighted);
 
   /// Returns the operation sketch feature
   /// \returns the sketch instance
@@ -80,6 +81,10 @@ signals:
   void planeSelected(double theX, double theY, double theZ);
 
 protected:
+  /// Virtual method called when operation started (see start() method for more description)
+  /// Default impl calls corresponding slot and commits immediately.
+  virtual void startOperation();
+
   /// Returns whether the sketch plane is set
   /// \return the boolean value whether the sketch is set
   bool hasSketchPlane() const;
index 07438b2d2e62169747a0da8849c4573d63a9f909..09dbdc74fc7ebf649d402d8654ae2fed333a48a9 100644 (file)
@@ -3,7 +3,7 @@
     <group id="Operations">
       <feature id="Part" title="New part" tooltip="Creates a new part" icon=":pictures/part_ico.png"/>
       <feature id="duplicate" title="Duplicate" tooltip="Duplicate selected object" icon=":icons/duplicate.png"/>
-      <feature id="remove" title="Remove"  tooltip="Remove selected object" icon=":icons/remove.png"/>
+      <feature id="remove" title="Remove part"  tooltip="Remove active part" icon=":icons/remove.png"/>
     </group>
   </workbench>
 </plugin>
index 13b61db1fbfaf04c26121633d179d7b75d351804..1d97cb2b051be4fd0e51d787f4f9591d8989b2b9 100644 (file)
@@ -35,14 +35,18 @@ void SketchPlugin_Sketch::execute()
 
 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
 {
-  std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
-
-  addPlane(1, 0, 0, aFaces); // YZ plane
-  addPlane(0, 1, 0, aFaces); // XZ plane
-  addPlane(0, 0, 1, aFaces); // XY plane
-  boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
-  setPreview(aCompound);
+  if (isPlaneSet()) {
+    setPreview(boost::shared_ptr<GeomAPI_Shape>());
+  }
+  else {
+    std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
 
+    addPlane(1, 0, 0, aFaces); // YZ plane
+    addPlane(0, 1, 0, aFaces); // XZ plane
+    addPlane(0, 0, 1, aFaces); // XY plane
+    boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
+    setPreview(aCompound);
+  }
   return getPreview();
 }
 
@@ -76,3 +80,11 @@ boost::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, cons
 
   return boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
 }
+
+bool SketchPlugin_Sketch::isPlaneSet()
+{
+  boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_NORM));
+
+  return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
+}
index ecdf0ee3af4ef44ed5d161a2eb1d593994f76b16..7c0894995afb358733a1aaf8b90be271f04b398c 100644 (file)
@@ -67,6 +67,10 @@ protected:
   /// \param theShapes the list of result shapes
   void addPlane(double theX, double theY, double theZ,
                 std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const;
+
+  /// Checks whether the plane is set in the sketch.
+  /// \returns the boolean state
+  bool isPlaneSet();
 };
 
 #endif
index d1ca2c2ed4b895c46237f14eeb63322c674fe33b..37c78f82a4aec5b3f23d24765e9a8a83bd4b6756 100644 (file)
@@ -7,6 +7,7 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Data.h>
 #include <Model_Events.h>
+#include <ModelAPI_Object.h>
 
 #include <Events_Loop.h>
 
@@ -58,7 +59,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
       if (aDoc == myDocument) {  // If root objects
         if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { // Update only Parts group
           // Add a new part
-          int aStart = myPartModels.size() + 1;
+          int aStart = myPartModels.size();
           XGUI_PartDataModel* aModel = new XGUI_PartDataModel(myDocument, this);
           aModel->setPartId(myPartModels.count());
           myPartModels.append(aModel);
@@ -100,6 +101,11 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
           int aStart = myPartModels.size() - 1;
           removeSubModel(aStart);
           removeRow(aStart, partFolderNode());
+          if (myActivePart && (!isPartSubModel(myActivePart))) {
+            myActivePart = 0;
+            myActivePartIndex = QModelIndex();
+            myModel->setItemsColor(ACTIVE_COLOR);
+          }
         } else { // Update top groups (other except parts
           QModelIndex aIndex = myModel->findGroup(aGroup);
           int aStart = myModel->rowCount(aIndex);
@@ -470,6 +476,7 @@ void XGUI_DocumentDataModel::deactivatePart()
   if (myActivePart) 
     myActivePart->setItemsColor(PASSIVE_COLOR);
   myActivePart = 0;
+  myActivePartIndex = QModelIndex();
   myModel->setItemsColor(ACTIVE_COLOR);
 }
  
@@ -484,11 +491,16 @@ Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const
 
 QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) const 
 {
+  FeaturePtr aFeature = theFeature;
+  if (!aFeature->data()) {
+    ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
+    aFeature = aObject->featureRef();
+  }
   int aRow = -1;
   XGUI_PartModel* aModel = 0;
   foreach (XGUI_PartModel* aPartModel, myPartModels) {
     aRow++;
-    if (aPartModel->part() == theFeature) {
+    if (aPartModel->part() == aFeature) {
       aModel = aPartModel;
       break;
     }
index 702c44fef8cd696cfcff8fb55c68b14ca98dfec1..258a59f8021fe2b6663f57dbac02b351f4151dad 100644 (file)
@@ -83,12 +83,13 @@ void XGUI_DataTree::commitData(QWidget* theEditor)
   if (aEditor) {
     QString aRes = aEditor->text();
     FeaturePtr aFeature = mySelectedData.first();
-    aFeature->document()->startOperation();
+    PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+    aMgr->rootDocument()->startOperation();
     if (aFeature->data())
       aFeature->data()->setName(qPrintable(aRes));
     else
       boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->setName(qPrintable(aRes));
-    aFeature->document()->finishOperation();
+    aMgr->rootDocument()->finishOperation();
   }
 }
 
index 389f81420925586f6724787be794a2a9e1a964bb..2c9efd2965bc95ca680ad9326aafde225423085c 100644 (file)
@@ -97,7 +97,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), SLOT(onOperationStopped(ModuleBase_Operation*)));
   connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
   connect(myOperationMgr, SIGNAL(operationStarted()), myActionsMgr, SLOT(update()));
-  connect(myOperationMgr, SIGNAL(operationStopped()), myActionsMgr, SLOT(update()));
+  connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), myActionsMgr, SLOT(update()));
   connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
 }
 
@@ -121,7 +121,6 @@ void XGUI_Workshop::startApplication()
   Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED);
   aLoop->registerListener(this, aFeatureUpdatedId);
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
 
   activateModule();
   if (myMainWindow) {
@@ -238,13 +237,6 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage)
     }
   }
 
-  // Process deletion of a part
-  if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) {
-    PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
-    if (aMgr->currentDocument() == aMgr->rootDocument())
-      activatePart(FeaturePtr()); // Activate PartSet
-  }
-
   //Update property panel on corresponding message. If there is no current operation (no
   //property panel), or received message has different feature to the current - do nothing.
   static Events_ID aFeatureUpdatedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED);
@@ -307,6 +299,7 @@ void XGUI_Workshop::onOperationStarted()
     myPropertyPanel->setModelWidgets(aFactory.getModelWidgets());
     myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
   }
+  updateCommandStatus();
 }
 
 //******************************************************
@@ -537,6 +530,8 @@ void XGUI_Workshop::onRedo()
   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
   PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
   DocumentPtr aDoc = aMgr->rootDocument();
+  if (aDoc->isOperation())
+    operationMgr()->abortOperation();
   aDoc->redo();
   updateCommandStatus();
 }