]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom.git
authorsbh <sergey.belash@opencascade.com>
Tue, 29 Apr 2014 07:37:19 +0000 (11:37 +0400)
committersbh <sergey.belash@opencascade.com>
Tue, 29 Apr 2014 07:37:19 +0000 (11:37 +0400)
Conflicts:
src/XGUI/XGUI_Workshop.h

1  2 
src/PartSet/PartSet_Module.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 9eece1559f9a44fc8d35bfa67c1c3497d0ca8d04,bc383d3019f745a6025c688d96652a46685c3315..5fb8796e0eedafb0be7ea2bf9e607af989b1f7a8
@@@ -12,6 -12,7 +12,7 @@@
  #include <XGUI_Workshop.h>
  #include <XGUI_OperationMgr.h>
  #include <XGUI_ViewWindow.h>
+ #include <XGUI_SelectionMgr.h>
  #include <XGUI_ViewPort.h>
  
  #include <Config_PointerMessage.h>
@@@ -19,7 -20,6 +20,7 @@@
  #include <Config_WidgetReader.h>
  #include <Events_Loop.h>
  #include <Events_Message.h>
 +#include <Events_Error.h>
  
  #include <GeomAPI_Shape.h>
  
@@@ -154,11 -154,11 +155,11 @@@ void PartSet_Module::onMouseReleased(QP
    ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
    PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
    if (aPreviewOp) {
-     XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
-     if (aViewer) {
+     XGUI_SelectionMgr* aSelector = myWorkshop->selector();
+     if (aSelector) {
        NCollection_List<TopoDS_Shape> aList;
-       aViewer->getSelectedShapes(aList);
-       XGUI_ViewWindow* aWindow = aViewer->activeViewWindow();
+       aSelector->selectedShapes(aList);
+       XGUI_ViewWindow* aWindow = myWorkshop->mainWindow()->viewer()->activeViewWindow();
        if (aWindow) {
          Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
          if ( !aView3d.IsNull() ) {
index dd6e1200fc321ab3db8b5f3fd42f04f45d916ab4,2655b569456ab43b28ea6227a5a35987696e4185..e36e3c26998e037642480ed913fb20c29556a4b4
@@@ -15,7 -15,6 +15,7 @@@
  #include "XGUI_OperationMgr.h"
  #include "XGUI_SalomeConnector.h"
  #include "XGUI_ActionsMgr.h"
 +#include "XGUI_ErrorDialog.h"
  
  #include <ModelAPI_PluginManager.h>
  #include <ModelAPI_Feature.h>
@@@ -23,7 -22,6 +23,7 @@@
  #include <ModelAPI_AttributeDocRef.h>
  
  #include <Events_Loop.h>
 +#include <Events_Error.h>
  #include <ModuleBase_PropPanelOperation.h>
  #include <ModuleBase_Operation.h>
  #include <Config_FeatureMessage.h>
@@@ -48,8 -46,7 +48,8 @@@
  #endif
  
  XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
 -  : QObject(), 
 +  : QObject(),
 +  myCurrentFile(QString()),
    myPartSetModule(NULL),
    mySalomeConnector(theConnector),
    myPropertyPanelDock(0),
    // So, displayer will be created on demand.
  
    mySelector = new XGUI_SelectionMgr(this);
+   connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(changeCurrentDocument()));
    myOperationMgr = new XGUI_OperationMgr(this);
    myActionsMgr = new XGUI_ActionsMgr(this);
 +  myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
 +
    connect(myOperationMgr, SIGNAL(operationStarted()),  this, SLOT(onOperationStarted()));
    connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
            this, SLOT(onOperationStopped(ModuleBase_Operation*)));
 +  connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
  }
  
  //******************************************************
@@@ -84,7 -79,6 +85,7 @@@ void XGUI_Workshop::startApplication(
    initMenu();
    //Initialize event listening
    Events_Loop* aLoop = Events_Loop::loop();
 +  aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
    //TODO(sbh): Implement static method to extract event id [SEID]
    Events_ID aFeatureId = aLoop->eventByName("FeatureEvent");
    aLoop->registerListener(this, aFeatureId);
@@@ -181,11 -175,13 +182,11 @@@ void XGUI_Workshop::processEvent(const 
  {
    static Events_ID aFeatureId = Events_Loop::loop()->eventByName("FeatureEvent");
    if (theMessage->eventID() == aFeatureId) {
 -    const Config_FeatureMessage* aFeatureMsg =
 -        dynamic_cast<const Config_FeatureMessage*>(theMessage);
 +    const Config_FeatureMessage* aFeatureMsg = dynamic_cast<const Config_FeatureMessage*>(theMessage);
      addFeature(aFeatureMsg);
      return;
    }
 -  const Config_PointerMessage* aPartSetMsg =
 -      dynamic_cast<const Config_PointerMessage*>(theMessage);
 +  const Config_PointerMessage* aPartSetMsg = dynamic_cast<const Config_PointerMessage*>(theMessage);
    if (aPartSetMsg) {
      ModuleBase_PropPanelOperation* anOperation =
          (ModuleBase_PropPanelOperation*)(aPartSetMsg->pointer());
      }
      return;
    }
 +  const Events_Error* anAppError = dynamic_cast<const Events_Error*>(theMessage);
 +  if (anAppError) {
 +      emit errorOccurred(QString::fromLatin1(anAppError->description()));
 +      myErrorDlg->show();
 +      myErrorDlg->raise();
 +      myErrorDlg->activateWindow();
 +  }
  
  #ifdef _DEBUG
    qDebug() << "XGUI_Workshop::ProcessEvent: "
@@@ -318,34 -307,9 +319,34 @@@ void XGUI_Workshop::connectWithOperatio
    connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
  }
  
 +/*
 + * Saves document with given name.
 + */
 +void XGUI_Workshop::saveDocument(QString theName)
 +{
 +  QApplication::restoreOverrideCursor();
 +  boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
 +  boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
 +  aDoc->save(theName.toLatin1().constData());
 +  QApplication::restoreOverrideCursor();
 +}
 +
  //******************************************************
  void XGUI_Workshop::onExit()
  {
 +  boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
 +  boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
 +  if(aDoc->isModified()) {
 +    int anAnswer = QMessageBox::question(
 +        myMainWindow, tr("Save current file"),
 +        tr("The document is modified, save before exit?"),
 +        QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
 +    if(anAnswer == QMessageBox::Save) {
 +      onSave();
 +    } else if (anAnswer == QMessageBox::Cancel) {
 +      return;
 +    }
 +  }
    qApp->exit();
  }
  
@@@ -355,7 -319,7 +356,7 @@@ void XGUI_Workshop::onNew(
    QApplication::setOverrideCursor(Qt::WaitCursor);
    if (objectBrowser() == 0) {
      createDockWidgets();
-     mySelector->connectObjectBrowser(objectBrowser());
+     mySelector->connectViewers();
    }
    showObjectBrowser();
    if (!isSalomeMode()) {
  //******************************************************
  void XGUI_Workshop::onOpen()
  {
 -  //QString aFileName = QFileDialog::getOpenFileName(mainWindow());
 +  //save current file before close if modified
 +  boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
 +  boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
 +  if(aDoc->isModified()) {
 +    //TODO(sbh): re-launch the app?
 +    int anAnswer = QMessageBox::question(
 +        myMainWindow, tr("Save current file"),
 +        tr("The document is modified, save before opening another?"),
 +        QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
 +    if(anAnswer == QMessageBox::Save) {
 +      onSave();
 +    } else if (anAnswer == QMessageBox::Cancel) {
 +      return;
 +    }
 +    aDoc->close();
 +    myCurrentFile = "";
 +  }
 +
 +  //show file dialog, check if readable and open
 +  myCurrentFile = QFileDialog::getOpenFileName(mainWindow());
 +  if(myCurrentFile.isEmpty())
 +    return;
 +  QFileInfo aFileInfo(myCurrentFile);
 +  if(!aFileInfo.exists() || !aFileInfo.isReadable()) {
 +    QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
 +    myCurrentFile = "";
 +    return;
 +  }
 +  QApplication::setOverrideCursor(Qt::WaitCursor);
 +  aDoc->load(myCurrentFile.toLatin1().constData());
 +  QApplication::restoreOverrideCursor();
    updateCommandStatus();
  }
  
  //******************************************************
  void XGUI_Workshop::onSave()
  {
 +  if(myCurrentFile.isEmpty()) {
 +    onSaveAs();
 +    return;
 +  }
 +  saveDocument(myCurrentFile);
    updateCommandStatus();
  }
  
  //******************************************************
  void XGUI_Workshop::onSaveAs()
  {
 -  //QString aFileName = QFileDialog::getSaveFileName(mainWindow());
 -  updateCommandStatus();
 +  QString aTemp = myCurrentFile;
 +  myCurrentFile = QFileDialog::getSaveFileName(mainWindow());
 +  if(myCurrentFile.isEmpty()) {
 +    myCurrentFile = aTemp;
 +    return;
 +  }
 +  QFileInfo aFileInfo(myCurrentFile);
 +  if(aFileInfo.exists() && !aFileInfo.isWritable()) {
 +    QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to save the file."));
 +    return;
 +  }
 +  onSave();
  }
  
  //******************************************************
@@@ -690,3 -609,25 +691,25 @@@ XGUI_Displayer* XGUI_Workshop::displaye
    }
    return myDisplayer;
  }
+ //******************************************************
+ void XGUI_Workshop::changeCurrentDocument()
+ {
+   QFeatureList aFeatures = objectBrowser()->selectedFeatures();
+   
+   // Set current document
+   if (aFeatures.size() > 0) {
+     FeaturePtr aFeature = aFeatures.first();
+     boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+     boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = aFeature->data()->docRef("PartDocument");
+     if (aDocRef)
+       aMgr->setCurrentDocument(aDocRef->value());
+   }
+ }
+ //******************************************************
+ void XGUI_Workshop::salomeViewerSelectionChanged()
+ {
+   emit salomeViewerSelection();
+ }
diff --combined src/XGUI/XGUI_Workshop.h
index 6406381ed243554dbcdd6accc9f70c71d4ba051d,7d75839cfae07bc44d117b5e762b673b8212a8cb..3f857ff12400d7f12e68d8f34869a788b504ac65
@@@ -19,7 -19,6 +19,7 @@@ class XGUI_OperationMgr
  class XGUI_SalomeConnector;
  class XGUI_ObjectsBrowser;
  class XGUI_ActionsMgr;
 +class XGUI_ErrorDialog;
  class ModuleBase_Operation;
  class ModuleBase_PropPanelOperation;
  
@@@ -73,6 -72,11 +73,11 @@@ public
    //! Returns Object browser
    XGUI_ObjectsBrowser* objectBrowser() const { return myObjectBrowser; }
  
+   void salomeViewerSelectionChanged();
+ signals:
+   void salomeViewerSelection();
  public slots:
    void updateCommandStatus();
  
    void hideObjectBrowser();
  
    void onFeatureTriggered();
 -
+   void changeCurrentDocument();
  
 +signals:
 +  void errorOccurred(const QString&);
 +
  protected:
    //Event-loop processing methods:
    void addFeature(const Config_FeatureMessage*);
    void connectWithOperation(ModuleBase_Operation* theOperation);
 +  void saveDocument(QString theName);
  
  protected slots:
    /// SLOT, that is called after the operation is started. Update workshop state according to
@@@ -122,17 -124,21 +128,17 @@@ private
    void createDockWidgets();
    void setPropertyPannelTitle(const QString& theTitle);
  
 -
 +  QString myCurrentFile;
    XGUI_MainWindow* myMainWindow;
    XGUI_Module* myPartSetModule;
 -
    XGUI_ObjectsBrowser* myObjectBrowser;
    QDockWidget* myPropertyPanelDock;
 -
    XGUI_SelectionMgr* mySelector;
    XGUI_Displayer* myDisplayer;
 -
    XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
    XGUI_ActionsMgr* myActionsMgr;
 -
 -
    XGUI_SalomeConnector* mySalomeConnector;
 +  XGUI_ErrorDialog* myErrorDlg;
  };
  
  #endif