From 49c936ff67ed86ca555213cf1b94c43121e6d982 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 11 Sep 2014 16:35:31 +0400 Subject: [PATCH] Open/Save in Salome mode --- src/NewGeom/NewGeom_DataModel.cpp | 40 ++++++++++++++++++++++++++-- src/NewGeom/NewGeom_Module.cpp | 12 ++++++++- src/NewGeom/NewGeom_Module.h | 4 +++ src/NewGeom/NewGeom_SalomeViewer.cpp | 5 +++- src/XGUI/XGUI_Displayer.cpp | 22 +++++++++++++-- src/XGUI/XGUI_MainWindow.cpp | 2 +- src/XGUI/XGUI_Workshop.h | 4 ++- 7 files changed, 81 insertions(+), 8 deletions(-) diff --git a/src/NewGeom/NewGeom_DataModel.cpp b/src/NewGeom/NewGeom_DataModel.cpp index cfe084655..3b494373f 100644 --- a/src/NewGeom/NewGeom_DataModel.cpp +++ b/src/NewGeom/NewGeom_DataModel.cpp @@ -1,6 +1,15 @@ #include "NewGeom_DataModel.h" #include "NewGeom_Module.h" +#include + +#include +#include +#include + +#include + + NewGeom_DataModel::NewGeom_DataModel(NewGeom_Module* theModule) : LightApp_DataModel(theModule), myModule(theModule) { @@ -12,11 +21,37 @@ NewGeom_DataModel::~NewGeom_DataModel() bool NewGeom_DataModel::open(const QString& thePath, CAM_Study* theStudy, QStringList theFiles) { + LightApp_DataModel::open( thePath, theStudy, theFiles ); + if (theFiles.size() == 0) + return false; + + QString aFile = theFiles.first(); + + SessionPtr aMgr = ModelAPI_Session::get(); + aMgr->load(qPrintable(aFile)); + myModule->setIsOpened(true); + myStudyPath = aFile; return true; } bool NewGeom_DataModel::save(QStringList& theFiles) { + LightApp_DataModel::save( theFiles ); + XGUI_Workshop* aWorkShop = myModule->workshop(); + std::list aFileNames; + + LightApp_Study* aStudy = dynamic_cast( myModule->application()->activeStudy() ); + std::string aTmpDir = aStudy->GetTmpDir(qPrintable(myStudyPath), true ); + theFiles.append(QString(aTmpDir.c_str())); + + aWorkShop->saveDocument(QString(aTmpDir.c_str()), aFileNames); + std::list::iterator aIt; + for (aIt = aFileNames.begin(); aIt != aFileNames.end(); ++aIt) { + QString aName((*aIt).c_str()); + aName.replace(QChar('\\'), QChar('/')); + int aN = aName.lastIndexOf('/'); + theFiles.append(aName.right(aName.length() - aN - 1)); + } return true; } @@ -38,12 +73,13 @@ bool NewGeom_DataModel::create(CAM_Study* theStudy) bool NewGeom_DataModel::isModified() const { - return false; + SessionPtr aMgr = ModelAPI_Session::get(); + return aMgr->isModified(); } bool NewGeom_DataModel::isSaved() const { - return true; + return !isModified(); } void NewGeom_DataModel::update(LightApp_DataObject* theObj, LightApp_Study* theStudy) diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index a02f11998..023a1ffb1 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -26,6 +27,8 @@ #include #include +#include + extern "C" { NewGeom_EXPORT CAM_Module* createModule() @@ -64,7 +67,7 @@ private: //****************************************************** NewGeom_Module::NewGeom_Module() : LightApp_Module("NewGeom"), - mySelector(0) + mySelector(0), myIsOpened(0) { myWorkshop = new XGUI_Workshop(this); myProxyViewer = new NewGeom_SalomeViewer(this); @@ -116,6 +119,13 @@ bool NewGeom_Module::activateModule(SUIT_Study* theStudy) myWorkshop->propertyPanel()->hide(); QtxPopupMgr* aMgr = popupMgr(); // Create popup manager action(myEraseAll)->setEnabled(false); + + if (myIsOpened) { + myWorkshop->objectBrowser()->rebuildDataTree(); + myWorkshop->updateCommandStatus(); + myIsOpened = false; + QTimer::singleShot(1000, myWorkshop, SLOT(displayAllResults())); + } } return isDone; } diff --git a/src/NewGeom/NewGeom_Module.h b/src/NewGeom/NewGeom_Module.h index 86c32772c..aad4775ca 100644 --- a/src/NewGeom/NewGeom_Module.h +++ b/src/NewGeom/NewGeom_Module.h @@ -77,6 +77,8 @@ Q_OBJECT XGUI_Workshop* workshop() const { return myWorkshop; } + void setIsOpened(bool theOpened) { myIsOpened = theOpened; } + public slots: virtual bool activateModule(SUIT_Study* theStudy); virtual bool deactivateModule(SUIT_Study* theStudy); @@ -99,6 +101,8 @@ Q_OBJECT NewGeom_SalomeViewer* myProxyViewer; QMap myNestedActions; + + bool myIsOpened; }; #endif diff --git a/src/NewGeom/NewGeom_SalomeViewer.cpp b/src/NewGeom/NewGeom_SalomeViewer.cpp index f63b3d77c..4d4a74ec9 100644 --- a/src/NewGeom/NewGeom_SalomeViewer.cpp +++ b/src/NewGeom/NewGeom_SalomeViewer.cpp @@ -19,7 +19,10 @@ NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent) //********************************************** Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const { - return mySelector->viewer()->getAISContext(); + if (mySelector && mySelector->viewer()) + return mySelector->viewer()->getAISContext(); + Handle(AIS_InteractiveContext) aNull; + return aNull; } //********************************************** diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 840ade671..7f1627c28 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -69,6 +69,8 @@ void XGUI_Displayer::display(ObjectPtr theObject, boost::shared_ptrimpl(); if (!anAISIO.IsNull()) { @@ -83,6 +85,8 @@ void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer) return; Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; boost::shared_ptr anObject = myResult2AISObjectMap[theObject]; if (anObject) { Handle(AIS_InteractiveObject) anAIS = anObject->impl(); @@ -154,6 +158,8 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer) } if (!aAISIO.IsNull()) { Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; aContext->Redisplay(aAISIO, isUpdateViewer); //if (aContext->HasOpenedContext()) { // aContext->Load(aAISIO, -1, true/*allow decomposition*/); @@ -165,6 +171,8 @@ void XGUI_Displayer::activateInLocalContext(ObjectPtr theResult, const std::list const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; // Open local context if there is no one if (!aContext->HasOpenedContext()) { aContext->ClearCurrents(false); @@ -201,6 +209,8 @@ void XGUI_Displayer::deactivate(ObjectPtr theObject) { if (isVisible(theObject)) { Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; boost::shared_ptr anObj = myResult2AISObjectMap[theObject]; Handle(AIS_InteractiveObject) anAIS = anObj->impl(); @@ -212,6 +222,8 @@ void XGUI_Displayer::activate(ObjectPtr theObject) { if (isVisible(theObject)) { Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; boost::shared_ptr anObj = myResult2AISObjectMap[theObject]; Handle(AIS_InteractiveObject) anAIS = anObj->impl(); @@ -223,6 +235,8 @@ void XGUI_Displayer::stopSelection(const QList& theResults, const boo const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; Handle(AIS_Shape) anAIS; QList::const_iterator anIt = theResults.begin(), aLast = theResults.end(); @@ -280,8 +294,10 @@ void XGUI_Displayer::setSelected(const QList& theResults, const bool } void XGUI_Displayer::eraseAll(const bool isUpdateViewer) - { - Handle(AIS_InteractiveContext) ic = AISContext(); +{ + Handle(AIS_InteractiveContext) ic = AISContext(); + if (ic.IsNull()) + return; ResultToAISMap::iterator aIt; for (aIt = myResult2AISObjectMap.begin(); aIt != myResult2AISObjectMap.end(); aIt++) { @@ -299,6 +315,8 @@ void XGUI_Displayer::eraseAll(const bool isUpdateViewer) void XGUI_Displayer::eraseDeletedResults(const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; ResultToAISMap::const_iterator aFIt = myResult2AISObjectMap.begin(), aFLast = myResult2AISObjectMap.end(); diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index 67edcd059..7fc26f0bf 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -257,7 +257,7 @@ void XGUI_MainWindow::updateTitle() { QString aTitle = myTitle; if (!myCurrentDir.isNull()) - aTitle += ":" + myCurrentDir; + aTitle += " - " + myCurrentDir; if (myIsModified) aTitle += "*"; setWindowTitle(aTitle); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index cf1c709a0..946e75c9d 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -202,6 +202,9 @@ signals: void activateLastPart(); + /// Display all results of the current document + void displayAllResults(); + protected: //Event-loop processing methods: void addFeature(const Config_FeatureMessage*); @@ -216,7 +219,6 @@ signals: QList getModuleCommands() const; - void displayAllResults(); void displayDocumentResults(DocumentPtr theDoc); void displayGroupResults(DocumentPtr theDoc, std::string theGroup); -- 2.39.2