XGUI_Workshop.h
XGUI_WorkshopListener.h
XGUI_InspectionPanel.h
+ XGUI_CompressFiles.h
)
SET(PROJECT_MOC_HEADERS
XGUI_Workshop.cpp
XGUI_WorkshopListener.cpp
XGUI_InspectionPanel.cpp
+ XGUI_CompressFiles.cpp
)
SET(PROJECT_RESOURCES
--- /dev/null
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#include "XGUI_CompressFiles.h"
+
+#include <QFile>
+#include <QFileInfo>
+#include <QDir>
+#include <QDataStream>
+
+
+
+
+bool XGUI_CompressFiles::compress(const QString& theFile, std::list<std::string> theFiles)
+{
+ QFile aOutFile(theFile);
+ if (aOutFile.open(QIODevice::WriteOnly)) {
+ QDataStream aOutStream(&aOutFile);
+
+ std::list<std::string>::const_iterator aIt;
+ for (aIt = theFiles.cbegin(); aIt != theFiles.cend(); ++aIt) {
+ QString aPathName((*aIt).c_str());
+ QFile aSrcFile(aPathName);
+ if (aSrcFile.open(QIODevice::ReadOnly)) {
+ QFileInfo aInfo(aSrcFile);
+ quint64 aSize = aInfo.size();
+ QString aName =
+ aPathName.right(aPathName.length() - aPathName.lastIndexOf(QDir::separator()) - 1);
+
+ aOutStream << aName << aSize;
+ aOutStream << qCompress(aSrcFile.readAll());
+ aSrcFile.close();
+ }
+ else {
+ aOutFile.close();
+ return false;
+ }
+ }
+ aOutFile.close();
+ }
+ else
+ return false;
+
+ return true;
+}
+
+
+bool XGUI_CompressFiles::uncompress(const QString& theFile, const QString& theDir)
+{
+ QFile aInFile(theFile);
+ QDir aDir(theDir);
+ if (!aDir.exists())
+ aDir.mkpath(theDir);
+ if (!aDir.isEmpty()) {
+ if (!aDir.removeRecursively())
+ return false;
+ aDir.mkdir(theDir);
+ }
+
+ if (aInFile.open(QIODevice::ReadOnly)) {
+ QDataStream aInStream(&aInFile);
+ do {
+ QString aFileName;
+ quint64 aSize;
+ aInStream >> aFileName;
+ aInStream >> aSize;
+
+ QFile aOutFile(theDir + QDir::separator() + aFileName);
+ if (aOutFile.open(QIODevice::WriteOnly)) {
+ QByteArray aContent;
+ aContent.resize(aSize);
+ aInStream >> aContent;
+ aOutFile.write(qUncompress(aContent));
+ aOutFile.close();
+ }
+ } while (!aInStream.atEnd());
+ aInFile.close();
+ }
+ return true;
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef XGUI_CompressFiles_H
+#define XGUI_CompressFiles_H
+
+#include "XGUI.h"
+
+#include <QString>
+
+#include <list>
+
+/**
+* \ingroup GUI
+* The class implements static methods for compressing/uncompressing files
+*/
+class XGUI_CompressFiles
+{
+public:
+
+ /// Compress list of file to an archive
+ /// \param theFile a name of compressed output file
+ /// \param theFiles a list of input files to compress
+ static bool compress(const QString& theFile, std::list<std::string> theFiles);
+
+ /// Uncompress files
+ /// \param theFile a compressed file
+ /// \param theDir an output directory for uncompressed files
+ static bool uncompress(const QString& theFile, const QString& theDir);
+
+};
+
+#endif
\ No newline at end of file
#include <XGUI_QtEvents.h>
#include <XGUI_DataModel.h>
#include <XGUI_InspectionPanel.h>
+#include <XGUI_CompressFiles.h>
#ifndef HAVE_SALOME
#include <AppElements_Button.h>
//#define DEBUG_FEATURE_NAME
//#define DEBUG_CLEAN_HISTORY
+
+static QString MyFilter(QObject::tr("OpenParts files (*.opp)"));
+
+
//******************************************************
XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
: QObject(),
- myCurrentDir(QString()),
myModule(NULL),
mySalomeConnector(theConnector),
myPropertyPanel(0),
//IMP: an attempt to use result selection with other selection modes
myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
myViewerSelMode.append(TopAbs_COMPSOLID);
+
+ qDebug("### Tmp: %s", qPrintable(myTmpDir.path()));
}
//******************************************************
delete myDisplayer;
delete myDataModelXMLReader;
+ clearTemporaryDir();
}
//******************************************************
} 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;
}
module()->closeDocument();
SessionPtr aSession = ModelAPI_Session::get();
aSession->closeAll();
- aSession->load(myCurrentDir.toLatin1().constData());
+
+ clearTemporaryDir();
+ XGUI_CompressFiles::uncompress(myCurrentFile, myTmpDir.path());
+
+ aSession->load(myTmpDir.path().toLatin1().constData());
myObjectBrowser->rebuildDataTree();
// Open first level of data tree
updateCommandStatus();
#ifndef HAVE_SALOME
- myMainWindow->setCurrentDir(myCurrentDir, true);
+ myMainWindow->setCurrentDir(myCurrentFile, true);
#endif
#ifdef _DEBUG
{
if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
return false;
- if (myCurrentDir.isEmpty()) {
+ if (myCurrentFile.isEmpty()) {
return onSaveAs();
}
SessionPtr aMgr = ModelAPI_Session::get();
aMgr->blockAutoUpdate(false);
std::list<std::string> aFiles;
- saveDocument(myCurrentDir, aFiles);
+ saveDocument(myTmpDir.path(), aFiles);
+ XGUI_CompressFiles::compress(myCurrentFile, aFiles);
+
updateCommandStatus();
#ifndef HAVE_SALOME
myMainWindow->setModifiedState(false);
{
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;
- }
- }
- myCurrentDir = aTempDir;
#ifndef HAVE_SALOME
- myMainWindow->setCurrentDir(myCurrentDir, false);
+ myCurrentFile = QFileDialog::getSaveFileName(desktop(), tr("Select name to save file..."),
+ QString(), MyFilter);
+ if (!myCurrentFile.isNull()) {
+ myMainWindow->setCurrentDir(myCurrentFile, false);
myMainWindow->setModifiedState(false);
+ }
#endif
return onSave();
}
QIcon(":pictures/autoapply_start.png"));
#endif
}
+
+
+void XGUI_Workshop::clearTemporaryDir()
+{
+ 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
#include <QObject>
#include <QKeySequence>
#include <QMap>
+#include <QTemporaryDir>
#ifndef HAVE_SALOME
class AppElements_Command;
/// Returns current module
ModuleBase_IModule* module() const { return myModule; }
- /// Returns current directory which contains data files
- QString currentDataDir() const { return myCurrentDir; }
+ /// Returns current file
+ QString currentDataFile() const { return myCurrentFile; }
- /// Returns current directory which contains data files
- void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
+ /// Returns current file
+ void setCurrentDataFile(const QString& theDir) { myCurrentFile = theDir; }
/// Save the current document into a directory
/// \param theName - path to the directory
/// Closes all in the current session and load the directory
/// \param theDirectory a path to directory
- void openDirectory(const QString& theDirectory);
+ void openFile(const QString& theDirectory);
void updateAutoComputeState();
/// \param theTimes number of applies the given action
void processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes);
+ /// Clear content of temporary directory
+ void clearTemporaryDir();
+
private:
#ifndef HAVE_SALOME
AppElements_MainWindow* myMainWindow; ///< desktop window
XGUI_ContextMenuMgr* myContextMenuMgr; ///< manager of context menu build
XGUI_ModuleConnector* myModuleConnector; ///< implementation of ModuleBase_IWorkshop
XGUI_WorkshopListener* myEventsListener; ///< processing of events
- QString myCurrentDir; ///< cached the last open directory
+ QString myCurrentFile; ///< cached the last open directory
QIntList myViewerSelMode; ///< selection modes set in the viewer
Config_DataModelReader* myDataModelXMLReader; ///< XML reader of data model
XGUI_InspectionPanel* myInspectionPanel; ///< container of feature attributes widgets
+ QTemporaryDir myTmpDir; ///< a direcory for uncompressed files
};
#endif