]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'MessagesGroups'
authormpv <mikhail.ponikarov@opencascade.com>
Thu, 22 May 2014 14:15:29 +0000 (18:15 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Thu, 22 May 2014 14:15:29 +0000 (18:15 +0400)
Conflicts:
src/SketchSolver/SketchSolver_ConstraintManager.cpp

1  2 
src/Model/Model_Document.cpp
src/SketchSolver/SketchSolver_ConstraintManager.cpp
src/XGUI/XGUI_Workshop.cpp

index 3f0378447e1e8b6854cca8b71f473f430db7dfac,662374984bd3b0b081d63566b2b3d8a7a169df61..806709ff24003c099fe34a4a2aa76840acbe7ac2
@@@ -179,7 -179,7 +179,7 @@@ void Model_Document::startOperation(
      myNestedStart = myTransactionsAfterSave;
    }
    // new command for this
 -  myDoc->NewCommand();
 +  myDoc->OpenCommand();
    // new command for all subs
    set<string>::iterator aSubIter = mySubs.begin();
    for(; aSubIter != mySubs.end(); aSubIter++)
@@@ -593,4 -593,11 +593,11 @@@ void Model_Document::synchronizeFeature
        aFLabIter.Next();
      }
    }
+   // after all updates, sends a message that groups of features were created or updated
+   boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->
+     setCheckTransactions(false);
+   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_CREATED));
+   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_DELETED));
+   boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->
+     setCheckTransactions(true);
  }
index a2db1ce05c03adc6130145ae1d4ff06a09491f14,d8ae5bcd2e21ae7a91f7f60d63ae9208ed7e7fe7..7caf4342ca625a72908582d28b85248bada6a7bb
@@@ -12,6 -12,7 +12,7 @@@
  #include <ModelAPI_AttributeRefList.h>
  #include <ModelAPI_Data.h>
  #include <Model_Events.h>
  #include <SketchPlugin_Constraint.h>
  #include <SketchPlugin_ConstraintCoincidence.h>
  #include <SketchPlugin_Line.h>
@@@ -21,6 -22,8 +22,8 @@@
  #include <math.h>
  #include <assert.h>
  
+ #include <set>
  /// Tolerance for value of parameters
  const double tolerance = 1.e-10;
  
@@@ -61,7 -64,7 +64,7 @@@ SketchSolver_ConstraintManager::SketchS
    Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
    Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
    Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
-   Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURES_MOVED));
+   Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_MOVED));
  }
  
  SketchSolver_ConstraintManager::~SketchSolver_ConstraintManager()
  void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessage)
  {
    if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED) ||
-       theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED))
+       theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED) || 
+       theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_MOVED))
    {
-     const Model_FeatureUpdatedMessage* aUpdateMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
+     const Model_FeatureUpdatedMessage* anUpdateMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
+     std::set< boost::shared_ptr<ModelAPI_Feature> > aFeatures = anUpdateMsg->features();
  
-     // Only sketches and constraints can be added by Create event
-     const std::string& aFeatureKind = aUpdateMsg->feature()->getKind();
-     if (aFeatureKind.compare("Sketch") == 0)
-     {
-       boost::shared_ptr<SketchPlugin_Feature> aSketch =
-         boost::dynamic_pointer_cast<SketchPlugin_Feature>(aUpdateMsg->feature());
-       if (aSketch)
-         changeWorkplane(aSketch);
-       return ;
-     }
-     boost::shared_ptr<SketchPlugin_Constraint> aConstraint =
-       boost::dynamic_pointer_cast<SketchPlugin_Constraint>(aUpdateMsg->feature());
-     if (aConstraint)
-       changeConstraint(aConstraint);
-     else
+     bool isModifiedEvt = theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_MOVED);
+     if (!isModifiedEvt)
      {
-       // Sketch plugin features can be only updated
-       boost::shared_ptr<SketchPlugin_Feature> aFeature =
-         boost::dynamic_pointer_cast<SketchPlugin_Feature>(aUpdateMsg->feature());
-       if (aFeature)
-         updateEntity(aFeature);
+       std::set< boost::shared_ptr<ModelAPI_Feature> >::iterator aFeatIter;
+       for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++)
+       {
+         // Only sketches and constraints can be added by Create event
+         const std::string& aFeatureKind = (*aFeatIter)->getKind();
+         if (aFeatureKind.compare("Sketch") == 0)
+         {
+           boost::shared_ptr<SketchPlugin_Feature> aSketch =
+             boost::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
 -          changeWorkplane(aSketch);
++          if (aSketch)
++            changeWorkplane(aSketch);
+           return ;
+         }
+         boost::shared_ptr<SketchPlugin_Constraint> aConstraint =
+           boost::dynamic_pointer_cast<SketchPlugin_Constraint>(*aFeatIter);
+         if (aConstraint)
+           changeConstraint(aConstraint);
+         else
+         {
+           // Sketch plugin features can be only updated
+           boost::shared_ptr<SketchPlugin_Feature> aFeature =
+             boost::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
+           if (aFeature)
+             updateEntity(aFeature);
+         }
+       }
      }
+     // Solve the set of constraints
+     resolveConstraints();
    }
    else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED))
    {
      const Model_FeatureDeletedMessage* aDeleteMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
-     if (aDeleteMsg->group().compare("Sketch") == 0)
+     const std::set<std::string>& aFeatureGroups = aDeleteMsg->groups();
+     // Find "Sketch" in groups. The constraint groups should be updated when an object removed from Sketch
+     std::set<std::string>::const_iterator aFGrIter;
+     for (aFGrIter = aFeatureGroups.begin(); aFGrIter != aFeatureGroups.end(); aFGrIter++)
+       if (aFGrIter->compare("Sketch") == 0)
+         break;
+     
+     if (aFGrIter != aFeatureGroups.end())
      {
        std::vector<SketchSolver_ConstraintGroup*>::iterator aGroupIter = myGroups.begin();
        while (aGroupIter != myGroups.end())
        }
      }
    }
-   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURES_MOVED))
-   {
-     // Solve the set of constraints
-     resolveConstraints();
-   }
  }
  
  bool SketchSolver_ConstraintManager::changeWorkplane(boost::shared_ptr<SketchPlugin_Feature> theSketch)
@@@ -238,10 -255,16 +256,16 @@@ void SketchSolver_ConstraintManager::fi
  boost::shared_ptr<SketchPlugin_Feature> SketchSolver_ConstraintManager::findWorkplaneForConstraint(
                boost::shared_ptr<SketchPlugin_Constraint> theConstraint) const
  {
+   // Already verified workplanes
+   std::set< boost::shared_ptr<SketchPlugin_Feature> > aVerified;
    std::vector<SketchSolver_ConstraintGroup*>::const_iterator aGroupIter;
    for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
    {
      boost::shared_ptr<SketchPlugin_Feature> aWP = (*aGroupIter)->getWorkplane();
+     if (aVerified.find(aWP) != aVerified.end())
+       continue;
      boost::shared_ptr<ModelAPI_AttributeRefList> aWPFeatures =
        boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aWP->data()->attribute(SKETCH_ATTR_FEATURES));
      std::list< boost::shared_ptr<ModelAPI_Feature> > aFeaturesList = aWPFeatures->list();
      for (anIter = aFeaturesList.begin(); anIter != aFeaturesList.end(); anIter++)
        if (*anIter == theConstraint)
          return aWP; // workplane is found
+     aVerified.insert(aWP);
    }
  
    return boost::shared_ptr<SketchPlugin_Feature>();
@@@ -259,6 -283,9 +284,9 @@@ void SketchSolver_ConstraintManager::re
    std::vector<SketchSolver_ConstraintGroup*>::iterator aGroupIter;
    for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
      (*aGroupIter)->resolveConstraints();
+   // Features may be updated => send events
+   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
  }
  
  
@@@ -311,7 -338,19 +339,19 @@@ bool SketchSolver_ConstraintManager::Sk
    if (myWorkplane.h != SLVS_E_UNKNOWN && myConstraints.empty())
      return true;
  
-   /// \todo Should be implemented
+   // Go through constraint entities and verify if some of them already in the group
+   for (int i = 0; i < CONSTRAINT_ATTR_SIZE; i++)
+   {
+     boost::shared_ptr<ModelAPI_AttributeRefAttr> aCAttrRef =
+       boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+         theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[i])
+       );
+     if (!aCAttrRef) continue;
+     if (myEntityMap.find(aCAttrRef->attr()) != myEntityMap.end())
+       return true;
+   }
+   // Entities did not found
    return false;
  }
  
index 9d064f210bbe9500ad01613bbf22880196a9efcd,7551bcfee44fecd81445b9753f4d4e920d8b7ffa..a5d6cddab790c12b436efa0c78a10778484ca614
@@@ -70,7 -70,7 +70,7 @@@ QString XGUI_Workshop::featureIcon(cons
  
  XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
    : QObject(),
 -  myCurrentFile(QString()),
 +  myCurrentDir(QString()),
    myPartSetModule(NULL),
    mySalomeConnector(theConnector),
    myPropertyPanel(0),
@@@ -204,16 -204,24 +204,26 @@@ void XGUI_Workshop::processEvent(const 
    static Events_ID aFeatureLoadedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED);
    if (theMessage->eventID() == aFeatureLoadedId) {
      const Config_FeatureMessage* aFeatureMsg = dynamic_cast<const Config_FeatureMessage*>(theMessage);
 -    addFeature(aFeatureMsg);
 +    if(!aFeatureMsg->isInternal()) {
 +      addFeature(aFeatureMsg);
 +    }
      return;
    }
    // Process creation of Part
    if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
      const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
-     FeaturePtr aFeature = aUpdMsg->feature();
-     if (aFeature->getKind() == "Part") {
+     std::set<FeaturePtr> aFeatures = aUpdMsg->features();
+     std::set<FeaturePtr>::const_iterator aIt;
+     bool aHasPart = false;
+     for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
+       FeaturePtr aFeature = (*aIt);
+       if (aFeature->getKind() == "Part") {
+         aHasPart = true;
+         break;
+       }
+     }
+     if (aHasPart) {
        //The created part will be created in Object Browser later and we have to activate it
        // only when it is created everywere
        QTimer::singleShot(50, this, SLOT(activateLastPart()));
    {
      const Model_FeatureUpdatedMessage* anUpdateMsg =
          dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
-     FeaturePtr aNewFeature = anUpdateMsg->feature();
+     std::set<FeaturePtr> aFeatures = anUpdateMsg->features();
      FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
-     if(aNewFeature == aCurrentFeature) {
-       myPropertyPanel->updateContentWidget(aCurrentFeature);
+     std::set<FeaturePtr>::const_iterator aIt;
+     for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
+       FeaturePtr aNewFeature = (*aIt);
+       if(aNewFeature == aCurrentFeature) {
+         myPropertyPanel->updateContentWidget(aCurrentFeature);
+         break;
+       } 
      }
    }
    //An operation passed by message. Start it, process and commit.
@@@ -442,21 -456,21 +458,21 @@@ void XGUI_Workshop::onOpen(
        return;
      }
      aDoc->close();
 -    myCurrentFile = "";
 +    myCurrentDir = "";
    }
  
    //show file dialog, check if readable and open
 -  myCurrentFile = QFileDialog::getExistingDirectory(mainWindow());
 -  if(myCurrentFile.isEmpty())
 +  myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
 +  if(myCurrentDir.isEmpty())
      return;
 -  QFileInfo aFileInfo(myCurrentFile);
 +  QFileInfo aFileInfo(myCurrentDir);
    if(!aFileInfo.exists() || !aFileInfo.isReadable()) {
      QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
 -    myCurrentFile = "";
 +    myCurrentDir = "";
      return;
    }
    QApplication::setOverrideCursor(Qt::WaitCursor);
 -  aDoc->load(myCurrentFile.toLatin1().constData());
 +  aDoc->load(myCurrentDir.toLatin1().constData());
    QApplication::restoreOverrideCursor();
    updateCommandStatus();
  }
  //******************************************************
  void XGUI_Workshop::onSave()
  {
 -  if(myCurrentFile.isEmpty()) {
 +  if(myCurrentDir.isEmpty()) {
      onSaveAs();
      return;
    }
 -  saveDocument(myCurrentFile);
 +  saveDocument(myCurrentDir);
    updateCommandStatus();
  }
  
  //******************************************************
  void XGUI_Workshop::onSaveAs()
  {
 -  QString aTemp = myCurrentFile;
 -  myCurrentFile = QFileDialog::getSaveFileName(mainWindow());
 -  if(myCurrentFile.isEmpty()) {
 -    myCurrentFile = aTemp;
 +  QFileDialog dialog(mainWindow());
 +  dialog.setWindowTitle(tr("Select directory to save files..."));
 +  dialog.setFileMode(QFileDialog::Directory);
 +  dialog.setFilter(tr("Folders (*)"));
 +  dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
 +  dialog.setViewMode(QFileDialog::Detail);
 +
 +  if(!dialog.exec()) {
      return;
    }
 -  QFileInfo aFileInfo(myCurrentFile);
 -  if(aFileInfo.exists() && !aFileInfo.isWritable()) {
 -    QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to save the file."));
 -    return;
 +  QString aTempDir = dialog.selectedFiles().first();
 +  QDir aDir(aTempDir);
 +  if(aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).isEmpty()) {
 +    int answer = QMessageBox::question(myMainWindow,
 +                                       QString(),
 +                                       tr("The folder already contains some files, save anyway?"),
 +                                       QMessageBox::Save|QMessageBox::Cancel);
 +    if(answer == QMessageBox::Cancel)
 +      return;
    }
 +  myCurrentDir = aTempDir;
    onSave();
  }