X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Workshop.cpp;h=e3db137e014486486f5838eb1501c447bd5b4a17;hb=bdf459165e3036046ce0ae3805b2391d569f9340;hp=907270967f0c51916dcaff3b39655251081a5afb;hpb=5c5547dac7feec007bc8804398cfc3111642b225;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 907270967..e3db137e0 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #ifndef HAVE_SALOME #include @@ -136,6 +137,7 @@ #include #include #include +#include #include @@ -168,10 +170,20 @@ QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end"); //#define DEBUG_FEATURE_NAME //#define DEBUG_CLEAN_HISTORY +#ifdef HAVE_SALOME +static QString MyFilter(QObject::tr("SHAPER files (*.shaper *.opp)")); +static QString MyFilter2(QObject::tr("SHAPER files (*.shaper)")); +static QString MyExtension(".shaper"); +#else +static QString MyFilter(QObject::tr("OpenParts files (*.opp);;All files (*.*)")); +static QString MyFilter2(QObject::tr("OpenParts files (*.opp)")); +static QString MyExtension(".opp"); +#endif + + //****************************************************** XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) : QObject(), - myCurrentDir(QString()), myModule(NULL), mySalomeConnector(theConnector), myPropertyPanel(0), @@ -186,7 +198,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) myOperationMgr = new XGUI_OperationMgr(this, 0); ModuleBase_IWorkshop* aWorkshop = moduleConnector(); // Has to be defined first in order to get errors and messages from other components - myEventsListener = new XGUI_WorkshopListener(aWorkshop); + myEventsListener = new XGUI_WorkshopListener(this); mySelectionActivate = new XGUI_SelectionActivate(aWorkshop); SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr(); @@ -298,6 +310,9 @@ XGUI_Workshop::~XGUI_Workshop(void) delete myDisplayer; delete myDataModelXMLReader; + delete mySelectionActivate; + delete myMenuMgr; + clearTemporaryDir(); } //****************************************************** @@ -427,13 +442,13 @@ void XGUI_Workshop::initMenu() salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT"); - aAction = salomeConnector()->addDesktopCommand("AUTOCOMPUTE_CMD", tr("Block auto-apply"), + aAction = salomeConnector()->addDesktopCommand("AUTOCOMPUTE_CMD", tr("Auto rebuild"), tr("Blocks immediate apply of modifications"), QIcon(":pictures/autoapply.png"), QKeySequence(), - true, "MEN_DESK_EDIT"); + false, "MEN_DESK_EDIT"); salomeConnector()->addActionInToolbar( aAction, aToolBarTitle ); - connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onAutoApply(bool))); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onAutoApply())); salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT"); @@ -490,17 +505,11 @@ void XGUI_Workshop::initMenu() aCommand->connectTo(this, SLOT(onOpen())); - aCommand = aGroup->addFeature("AUTOCOMPUTE_CMD", tr("Block auto-apply"), + aCommand = aGroup->addFeature("AUTOCOMPUTE_CMD", tr("Auto rebuild"), tr("Blocks immediate apply of modifications"), - QIcon(":pictures/autoapply.png"), QString(), - QKeySequence(), true, true); - aCommand->setChecked(ModelAPI_Session::get()->isAutoUpdateBlocked()); - aCommand->connectTo(this, SLOT(onAutoApply(bool))); - - - aCommand = aGroup->addFeature("EXEC_CMD", tr("Launch script"), tr("Launch Python script file"), - QIcon(":pictures/assembly.png"), QKeySequence()); - aCommand->connectTo(this, SLOT(onFileExec())); + QIcon(":pictures/autoapply_start.png"), QKeySequence()); + //aCommand->setChecked(ModelAPI_Session::get()->isAutoUpdateBlocked()); + aCommand->connectTo(this, SLOT(onAutoApply())); aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"), QIcon(":pictures/preferences.png"), QKeySequence::Preferences); @@ -596,14 +605,14 @@ void XGUI_Workshop::onHelpActionClicked() if (!aHelpPage.isEmpty()) { QString aDocDir; const QChar aSep = QDir::separator(); - QString platform; - SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr(); -#ifdef WIN32 - platform = "winapplication"; -#else - platform = "application"; -#endif - QString aBrowserName = aResMgr->stringValue("ExternalBrowser", platform); +// QString platform; +// SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr(); +//#ifdef WIN32 +// platform = "winapplication"; +//#else +// platform = "application"; +//#endif +// QString aBrowserName = aResMgr->stringValue("ExternalBrowser", platform); #ifdef HAVE_SALOME QString aDir(getenv("SHAPER_ROOT_DIR")); @@ -615,9 +624,11 @@ void XGUI_Workshop::onHelpActionClicked() QString aDir(getenv("OPENPARTS_ROOT_DIR")); aDocDir = aDir + aSep + "doc" + aSep + "gui"; #endif - QStringList aParams; - aParams << aDocDir + aSep + aHelpPage; - QProcess::startDetached(aBrowserName, aParams); + QString aFileName = aDocDir + aSep + aHelpPage; + if (QFile::exists(aFileName)) { + QUrl aUrl = QUrl::fromLocalFile(aFileName); + QDesktopServices::openUrl(aUrl); + } } } } @@ -916,25 +927,26 @@ void XGUI_Workshop::onOpen() } else if (anAnswer == QMessageBox::Cancel) { return; } - myCurrentDir = ""; + myCurrentFile = QString(); } //show file dialog, check if readable and open - QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory")); - openDirectory(aDirectory); + QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Open file"), QString(), MyFilter); + if (!aFile.isNull()) + openFile(aFile); } //****************************************************** -void XGUI_Workshop::openDirectory(const QString& theDirectory) +void XGUI_Workshop::openFile(const QString& theDirectory) { - myCurrentDir = theDirectory; - if (myCurrentDir.isEmpty()) + myCurrentFile = theDirectory; + if (myCurrentFile.isEmpty()) return; - QFileInfo aFileInfo(myCurrentDir); + QFileInfo aFileInfo(myCurrentFile); if (!aFileInfo.exists() || !aFileInfo.isReadable()) { QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file.")); - myCurrentDir = ""; + myCurrentFile = QString(); return; } @@ -942,7 +954,12 @@ void XGUI_Workshop::openDirectory(const QString& theDirectory) module()->closeDocument(); SessionPtr aSession = ModelAPI_Session::get(); aSession->closeAll(); - aSession->load(myCurrentDir.toLatin1().constData()); + + clearTemporaryDir(); + if (!XGUI_CompressFiles::uncompress(myCurrentFile, myTmpDir.path())) + return; + + aSession->load(myTmpDir.path().toLatin1().constData()); myObjectBrowser->rebuildDataTree(); // Open first level of data tree @@ -953,7 +970,7 @@ void XGUI_Workshop::openDirectory(const QString& theDirectory) updateCommandStatus(); #ifndef HAVE_SALOME - myMainWindow->setCurrentDir(myCurrentDir, true); + myMainWindow->setCurrentDir(myCurrentFile, true); #endif #ifdef _DEBUG @@ -1049,7 +1066,7 @@ bool XGUI_Workshop::onSave() { if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage)) return false; - if (myCurrentDir.isEmpty()) { + if (myCurrentFile.isEmpty()) { return onSaveAs(); } SessionPtr aMgr = ModelAPI_Session::get(); @@ -1057,7 +1074,10 @@ bool XGUI_Workshop::onSave() aMgr->blockAutoUpdate(false); std::list aFiles; - saveDocument(myCurrentDir, aFiles); + saveDocument(myTmpDir.path(), aFiles); + if (!XGUI_CompressFiles::compress(myCurrentFile, aFiles)) + return false; + updateCommandStatus(); #ifndef HAVE_SALOME myMainWindow->setModifiedState(false); @@ -1070,34 +1090,17 @@ bool XGUI_Workshop::onSaveAs() { if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage)) return false; - QFileDialog dialog(desktop()); - dialog.setWindowTitle(tr("Select directory to save files...")); - dialog.setFileMode(QFileDialog::Directory); - dialog.setFilter(QDir::AllDirs); - dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly); - dialog.setViewMode(QFileDialog::Detail); - - if (!dialog.exec()) { - return false; - } - - QString aTempDir = dialog.selectedFiles().first(); - QDir aDir(aTempDir); - if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) { - int answer = QMessageBox::question( - desktop(), - // Title of the dialog which asks user if he wants to save study - // in existing non-empty folder - tr("Save"), - tr("The directory already contains some files, save anyway?"), - QMessageBox::Save | QMessageBox::Cancel); - if (answer == QMessageBox::Cancel) { - return false; + myCurrentFile = QFileDialog::getSaveFileName(desktop(), tr("Select name to save file..."), + QString(), MyFilter2); + if (!myCurrentFile.isNull()) { + if (!myCurrentFile.endsWith(MyExtension)) { + myCurrentFile += MyExtension; } } - myCurrentDir = aTempDir; + else + return false; #ifndef HAVE_SALOME - myMainWindow->setCurrentDir(myCurrentDir, false); + myMainWindow->setCurrentDir(myCurrentFile, false); myMainWindow->setModifiedState(false); #endif return onSave(); @@ -1329,7 +1332,10 @@ void XGUI_Workshop::updateCommandStatus() aCmd->setEnabled(myModule->canRedo()); } else if (aId == "AUTOCOMPUTE_CMD") { - aCmd->setChecked(aMgr->isAutoUpdateBlocked()); + //aCmd->setChecked(aMgr->isAutoUpdateBlocked()); + aCmd->setIcon(aMgr->isAutoUpdateBlocked() ? + QIcon(":pictures/autoapply_stop.png") : + QIcon(":pictures/autoapply_start.png")); } else // Enable all commands @@ -2495,11 +2501,14 @@ void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible) //************************************************************** void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList) { + QObjectPtrList aSrcList = theList; // Hide all displayed objects QObjectPtrList aList = myDisplayer->displayedObjects(); foreach (ObjectPtr aObj, aList) { - if (module()->canEraseObject(aObj)) + if ((!aSrcList.contains(aObj)) && (module()->canEraseObject(aObj))) aObj->setDisplayed(false); + else + aSrcList.removeAll(aObj); } //Do not use eraseAll if you didn't send Redisplay event: //all objects are erased from viewer, but considered as displayed in displayer @@ -2511,7 +2520,7 @@ void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList) #endif std::set anObjects; - foreach (ObjectPtr aObj, theList) { + foreach (ObjectPtr aObj, aSrcList) { anObjects.insert(aObj); } @@ -2519,7 +2528,7 @@ void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList) return; // Show only objects from the list - foreach (ObjectPtr aObj, theList) { + foreach (ObjectPtr aObj, aSrcList) { aObj->setDisplayed(true); } Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); @@ -2714,9 +2723,7 @@ void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects) } if (aSelList.count() > theObjects.count()) { // if something was found - bool aBlocked = objectBrowser()->blockSignals(true); objectBrowser()->setObjectsSelected(aSelList); - objectBrowser()->blockSignals(aBlocked); objectBrowser()->ensureVisible(aNewSel.first()); } if (aHasHidden) @@ -2743,9 +2750,7 @@ void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects) } if (aSelList.count() > theObjects.count()) { // if something was found - bool aBlocked = objectBrowser()->blockSignals(true); objectBrowser()->setObjectsSelected(aSelList); - objectBrowser()->blockSignals(aBlocked); objectBrowser()->ensureVisible(aNewSel.first()); } } @@ -2823,26 +2828,45 @@ void XGUI_Workshop::moveOutFolder(bool isBefore) updateCommandStatus(); } -#ifndef HAVE_SALOME -#include -void XGUI_Workshop::onFileExec() +void XGUI_Workshop::onAutoApply() { - QString aScript = QFileDialog::getOpenFileName(myMainWindow, tr("Open script"), - QString(), "Python script (*.py)"); + SessionPtr aMgr = ModelAPI_Session::get(); + bool isBlocked = aMgr->isAutoUpdateBlocked(); + aMgr->blockAutoUpdate(!isBlocked); +} - if (!aScript.isNull()) { - PyConsole_Console* aConsole = myMainWindow->pythonConsole(); - aConsole->execAndWait(QString("f = open('%1', 'rb')").arg(aScript)); - QString aExecStr = - QString("exec(compile(f.read(), '%1', 'exec'))").arg(aScript); - aConsole->execAndWait(aExecStr); - aConsole->execAndWait("f.close()"); +void XGUI_Workshop::updateAutoComputeState() +{ + SessionPtr aMgr = ModelAPI_Session::get(); + bool isComputeBlocked = aMgr->isAutoUpdateBlocked(); +#ifdef HAVE_SALOME + QAction* aUpdateCmd; + QList aCommands = mySalomeConnector->commandList(); + foreach(QAction* aCmd, aCommands) { + if (aCmd->data().toString() == "AUTOCOMPUTE_CMD") { + aUpdateCmd = aCmd; + break; + } } -} + aUpdateCmd->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") : + QIcon(":pictures/autoapply_start.png")); +#else + AppElements_MainMenu* aMenuBar = myMainWindow->menuObject(); + AppElements_Command* aUpdateCmd = aMenuBar->feature("AUTOCOMPUTE_CMD"); + aUpdateCmd->button()->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") : + QIcon(":pictures/autoapply_start.png")); #endif +} + -void XGUI_Workshop::onAutoApply(bool isToggle) +void XGUI_Workshop::clearTemporaryDir() { - SessionPtr aMgr = ModelAPI_Session::get(); - aMgr->blockAutoUpdate(isToggle); + QDir aDir(myTmpDir.path()); + if (!aDir.isEmpty()) { + QStringList aEntries; + aDir.entryList(aEntries); + foreach(QString aFile, aEntries) { + aDir.remove(aFile); + } + } } \ No newline at end of file