-// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019 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
//
// 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
+// 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>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "XGUI_Workshop.h"
#include <XGUI_QtEvents.h>
#include <XGUI_DataModel.h>
#include <XGUI_InspectionPanel.h>
+#include <XGUI_CompressFiles.h>
#ifndef HAVE_SALOME
#include <AppElements_Button.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_ResultField.h>
//#include <PartSetPlugin_Part.h>
#include <Events_InfoMessage.h>
#include <Events_LongOp.h>
+#include <GeomAPI_Pnt.h>
+
#include <ModuleBase_IModule.h>
#include <ModuleBase_IViewer.h>
#include <ModuleBase_Operation.h>
#include <ModuleBase_ModelWidget.h>
#include <ModuleBase_ResultPrs.h>
#include <ModuleBase_ActionIntParameter.h>
+#include <ModuleBase_IStepPrs.h>
#include <Config_Common.h>
#include <Config_FeatureMessage.h>
#include <QAction>
#include <QDesktopWidget>
#include <QProcess>
+#include <QDesktopServices>
#include <iterator>
//#define DEBUG_FEATURE_NAME
//#define DEBUG_CLEAN_HISTORY
+#ifdef HAVE_SALOME
+static QString MyFilter(QObject::tr("SHAPER files (*.shaper *.cadbld)"));
+static QString MyFilter2(QObject::tr("SHAPER files (*.shaper)"));
+static QString MyExtension(".shaper");
+#else
+static QString MyFilter(QObject::tr("CAD Builder files (*.cadbld);;All files (*.*)"));
+static QString MyFilter2(QObject::tr("CAD Builder files (*.cadbld)"));
+static QString MyExtension(".cadbld");
+#endif
+
+
//******************************************************
XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
: QObject(),
- myCurrentDir(QString()),
myModule(NULL),
mySalomeConnector(theConnector),
myPropertyPanel(0),
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();
#ifndef HAVE_SALOME
connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
- onTrihedronVisibilityChanged(true);
+ myDisplayer->displayTrihedron(true);
#endif
connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
delete myDisplayer;
delete myDataModelXMLReader;
+ delete mySelectionActivate;
+ delete myMenuMgr;
+ clearTemporaryDir();
}
//******************************************************
QKeySequence::Undo, false,
"MEN_DESK_EDIT");
QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
- salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
+ salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
+ //aAction = salomeConnector()->addDesktopCommand("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
+ // tr("Blocks immediate apply of modifications"),
+ // QIcon(":pictures/autoapply.png"), QKeySequence(),
+ // false, "MEN_DESK_EDIT");
+ //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
+
+ //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onAutoApply()));
+
+ salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
+
+
+ // Add commands to a file menu
aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
tr("Export the current document into a native file"),
QIcon(), QKeySequence(),
QIcon(":pictures/open.png"), QKeySequence::Open);
aCommand->connectTo(this, SLOT(onOpen()));
+
+ aCommand = aGroup->addFeature("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
+ tr("Blocks immediate apply of modifications"),
+ 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);
aCommand->connectTo(this, SLOT(onPreferences()));
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"));
"salome" + aSep + "gui" + aSep + "SHAPER";
}
#else
- QString aDir(getenv("OPENPARTS_ROOT_DIR"));
- aDocDir = aDir + aSep + "doc";
+ QString aDir(getenv("CADBUILDER_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);
+ }
}
}
}
myModule->propertyPanelDefined(theOperation);
#ifndef DEBUG_FEATURE_NAME
- myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
+ myPropertyPanel->setWindowTitle(ModuleBase_Tools::translate("workshop",
+ theOperation->getDescription()->description().toStdString()));
#else
std::string aFeatureName = aFeature->name();
myPropertyPanel->setWindowTitle(QString("%1: %2")
- .arg(theOperation->getDescription()->description())
- .arg(aFeatureName.c_str()));
+ .arg(translate(theOperation->getDescription()->description()))
+ .arg(translate(aFeatureName.c_str())));
#endif
myErrorMgr->setPropertyPanel(myPropertyPanel);
if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
fillPropertyPanel(theOperation);
connectToPropertyPanel(true);
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (theOperation);
+ if (aFOperation)
+ myPropertyPanel->updateApplyPlusButton(aFOperation->feature());
+ else
+ myPropertyPanel->updateApplyPlusButton(FeaturePtr());
}
updateCommandStatus();
//save current file before close if modified
SessionPtr aSession = ModelAPI_Session::get();
if (aSession->isModified()) {
- //TODO(sbh): re-launch the app?
int anAnswer = QMessageBox::question(
desktop(), tr("Save current file"),
tr("The document is modified, save before opening another?"),
} 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);
+ qreal aRatio = ModuleBase_Tools::currentPixelRatio();
+ // If the ratio is > 1 (HD screen) then QT has a bug in
+ // displaying of system open file dialog (too small)
+ QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Open file"), QString(), MyFilter,
+ Q_NULLPTR, ((aRatio > 1)? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
+ 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();
+ if (!XGUI_CompressFiles::uncompress(myCurrentFile, myTmpDir.path()))
+ return;
+
+ 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
void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
{
XGUI_Displayer* aDisplayer = displayer();
- if (aDisplayer)
+ if (aDisplayer) {
aDisplayer->displayTrihedron(theState);
+ aDisplayer->updateViewer();
+ }
}
//******************************************************
{
if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
return false;
- if (myCurrentDir.isEmpty()) {
+ if (myCurrentFile.isEmpty()) {
return onSaveAs();
}
+ SessionPtr aMgr = ModelAPI_Session::get();
+ if (aMgr->isAutoUpdateBlocked())
+ aMgr->blockAutoUpdate(false);
+
std::list<std::string> aFiles;
- saveDocument(myCurrentDir, aFiles);
- updateCommandStatus();
+ // issue #2899: create a temporary directory, save and then remove it
+#ifdef HAVE_SALOME
+ std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("SALOME_TMP_DIR");
+#else
+ std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("");
+#endif
+ saveDocument(QString(aTmpDir.c_str()), aFiles);
+ bool aResult = XGUI_CompressFiles::compress(myCurrentFile, aFiles);
+ XGUI_Tools::removeTemporaryFiles(aTmpDir, aFiles);
+
+ if (aResult) {
+ updateCommandStatus();
#ifndef HAVE_SALOME
myMainWindow->setModifiedState(false);
#endif
- return true;
+ }
+ return aResult;
}
//******************************************************
{
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;
+ qreal aRatio = ModuleBase_Tools::currentPixelRatio();
+ myCurrentFile = QFileDialog::getSaveFileName(desktop(), tr("Select name to save file..."),
+ QString(), MyFilter2,
+ Q_NULLPTR, ((aRatio > 1) ? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
+ 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();
void XGUI_Workshop::onWidgetObjectUpdated()
{
operationMgr()->onValidateOperation();
+ myDisplayer->updateViewer();
}
//******************************************************
CREATE_FUNC crtInst = 0;
#ifdef WIN32
- HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
+ HINSTANCE modLib = ::LoadLibraryA(qPrintable(libName));
if (!modLib) {
LPVOID lpMsgBuf;
::FormatMessage(
else
aCmd->setEnabled(myModule->canRedo());
}
+ else if (aId == "AUTOCOMPUTE_CMD") {
+ aCmd->setIcon(aMgr->isAutoUpdateBlocked() ?
+ QIcon(":pictures/autoapply_stop.png") :
+ QIcon(":pictures/autoapply_start.png"));
+ }
else
// Enable all commands
aCmd->setEnabled(true);
{
QDockWidget* aObjDock = new QDockWidget(theParent);
aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
- Qt::RightDockWidgetArea |
- Qt::BottomDockWidgetArea);
+ Qt::RightDockWidgetArea);
aObjDock->setWindowTitle(tr("Object browser"));
aObjDock->setStyleSheet(
"::title { position: relative; padding-left: 5px; text-align: left center }");
myModule->customizeObjectBrowser(myObjectBrowser);
aObjDock->setWidget(myObjectBrowser);
+ connect(myObjectBrowser, SIGNAL(sizeChanged()), SLOT(onDockSizeChanged()));
+
myContextMenuMgr->connectObjectBrowser();
return aObjDock;
}
myPropertyPanel->setupActions(myActionsMgr);
myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
- Qt::RightDockWidgetArea |
- Qt::BottomDockWidgetArea);
+ Qt::RightDockWidgetArea);
aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
+
hidePanel(myPropertyPanel); ///<! Invisible by default
myFacesPanel = new XGUI_FacesPanel(aDesktop, myModuleConnector);
Qt::RightDockWidgetArea);
aDesktop->addDockWidget(Qt::RightDockWidgetArea, myInspectionPanel);
+ myInspectionPanel->hide();
+
aDesktop->addDockWidget(
#ifdef HAVE_SALOME
Qt::RightDockWidgetArea,
// the property panel is active window of the desktop, when it is
// hidden, it is undefined which window becomes active. By this reason
// it is defined to perform the desktop as the active window.
- // in SALOME mode, workstack made the PyConsole the active window,
+ // in SALOME mode, work-stack made the PyConsole the active window,
// set the focus on it. As a result, shortcuts of the application, like
// are processed by this console. For example Undo actions.
// It is possible that this code is to be moved to SHAPER package
changeColor(aObjects);
else if (theId == "DEFLECTION_CMD")
changeDeflection(aObjects);
-#ifdef USE_TRANSPARENCY
else if (theId == "TRANSPARENCY_CMD")
changeTransparency(aObjects);
-#endif
else if (theId == "SHOW_CMD") {
showObjects(aObjects, true);
mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
highlightResults(aObjects);
} else if (theId == "SHOW_FEATURE_CMD") {
highlightFeature(aObjects);
+ } else if (theId == "SET_VIEW_NORMAL_CMD") {
+ setNormalView();
+ } else if (theId == "SET_VIEW_INVERTEDNORMAL_CMD") {
+ setNormalView(true);
}
#ifdef TINSPECTOR
else if (theId == "TINSPECTOR_VIEW") {
#ifdef DEBUG_WITH_MESSAGE_REPORT
MyTCommunicator->RegisterPlugin("TKMessageView");
#endif
- MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
+ //MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
//MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
MyTCommunicator->Init(aParameters);
bool hasFolder = false;
ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
hasResultInHistory, hasFolder);
- if (!(hasFeature || hasParameter || hasFolder))
+ if (!(hasResult || hasFeature || hasParameter || hasFolder))
return;
+ // Remove from the list non-deletable objects: infinite constructions which are not in history
+ bool notDelete = true;
+ QObjectPtrList::iterator aIt;
+ for (aIt = anObjects.begin(); aIt != anObjects.end(); aIt++) {
+ ObjectPtr aObj = (*aIt);
+ ResultConstructionPtr aConstr = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
+ if (aFeature) {
+ notDelete = (!aFeature->isInHistory()) && aConstr->isInfinite();
+ if (notDelete) {
+ anObjects.removeAll(aObj);
+ aIt--;
+ }
+ }
+ }
// delete objects
std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
std::set<FeaturePtr> aFeatures;
}
}
}
+ // remove results selected
+ std::list<ResultPtr> aResults;
+ for(QObjectPtrList::const_iterator anIt = anObjects.begin(); anIt != anObjects.end(); anIt++) {
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*anIt);
+ if (aRes.get() && aRes->data()->isValid() && !aRes->data()->isDeleted() &&
+ aRes->groupName() != ModelAPI_ResultGroup::group() && // don't remove groups and fields
+ aRes->groupName() != ModelAPI_ResultField::group()) // because they are badly selected
+ aResults.push_back(aRes);
+ }
+ if (!aResults.empty()) {
+ ModelAPI_Tools::removeResults(aResults);
+ }
if (aDone)
operationMgr()->commitOperation();
else
operationMgr()->abortOperation(operationMgr()->currentOperation());
+
+ myDisplayer->updateViewer();
}
//**************************************************************
ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
// find for each object whether all reference values are in the map as key, that means that there
// is no other reference in the model to this object, so it might be removed by cleaning history
- // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
- // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
+ // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - can't be deleted, dependency to bool_1
+ // ext_1(bool_1, sk_3) - can't be deleted, dependency to bool_1
// vertex_1()
- // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
- // ext_2(bool_1) - cann't be deleted, dependency to bool_1
+ // sk_2(ext_2) + (bool_1) - can't be deleted, dependency to bool_1
+ // ext_2(bool_1) - can't be deleted, dependency to bool_1
// sk_3()
// Information: bool_1 is not selected
std::set<FeaturePtr> anUnusedObjects;
QString anUnusedNames = aNames.join(", ");
QString anActionId = "CLEAN_HISTORY_CMD";
- QString aDescription = contextMenuMgr()->action(anActionId)->text();
+ QString aDescription = ModuleBase_Tools::translate("workshop",
+ contextMenuMgr()->action(anActionId)->text().toStdString());
QMessageBox aMessageBox(desktop());
aMessageBox.setWindowTitle(aDescription);
}
//**************************************************************
+bool compareFeature(const FeaturePtr& theF1, const FeaturePtr& theF2) {
+ DocumentPtr aDoc = theF1->document();
+ return aDoc->index(theF1) < aDoc->index(theF2);
+}
void XGUI_Workshop::moveObjects()
{
if (!abortAllOperations())
SessionPtr aMgr = ModelAPI_Session::get();
- QString anActionId = "MOVE_CMD";
- QString aDescription = contextMenuMgr()->action(anActionId)->text();
- aMgr->startOperation(aDescription.toStdString());
-
QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
// It is necessary to clear selection in order to avoid selection changed event during
// moving and negative consequences connected with processing of already moved items
if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
return;
+ QString anActionId = "MOVE_CMD";
+ QString aDescription = contextMenuMgr()->action(anActionId)->text();
+ aMgr->startOperation(aDescription.toStdString());
+
+ // Sort features by index in document
+ std::list<FeaturePtr> aFList(aFeatures.begin(), aFeatures.end());
+ aFList.sort(compareFeature);
+
DocumentPtr anActiveDocument = aMgr->activeDocument();
FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
- std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
+ std::list<FeaturePtr>::const_iterator anIt = aFList.begin(), aLast = aFList.end();
for (; anIt != aLast; anIt++) {
FeaturePtr aFeature = *anIt;
if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
aCurrentFeature = anActiveDocument->currentFeature(true);
}
aMgr->finishOperation();
+ updateCommandStatus();
}
//**************************************************************
bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
{
if (theActionName == "COLOR_CMD" ||
- theActionName == "DEFLECTION_CMD"
-#ifdef USE_TRANSPARENCY
- || theActionName == "TRANSPARENCY_CMD"
-#endif
- ) {
+ theActionName == "DEFLECTION_CMD" ||
+ theActionName == "TRANSPARENCY_CMD") {
QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
std::set<std::string> aTypes;
aColorAttr->setValue(1, theColor[1]);
aColorAttr->setValue(2, theColor[2]);
}
+ static const Events_ID kRedisplayEvent =
+ Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
}
//**************************************************************
AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
if (aDeflectionAttr.get() != NULL)
aDeflectionAttr->setValue(theDeflection);
+ static const Events_ID kRedisplayEvent =
+ Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
}
//**************************************************************
AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
if (anAttribute.get() != NULL)
anAttribute->setValue(theTransparency);
+ static const Events_ID kRedisplayEvent =
+ Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
}
//**************************************************************
if (aResult.get()) {
aCurrentValue = XGUI_CustomPrs::getResultTransparency(aResult);
}
- else {
- // TODO: remove the obtaining a property from the AIS object
- // this does not happen never because:
- // 1. The property can be changed only on results
- // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
- AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
- if (anAISObj.get()) {
- aCurrentValue = anAISObj->getDeflection();
- }
- }
if (aCurrentValue > 0)
break;
}
return;
if (!abortAllOperations())
- return;
+ return;
// 2. show the dialog to change the value
XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
- aDlg->setWindowTitle("Transparency");
+ aDlg->setWindowTitle(tr("Transparency"));
XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
this, SLOT(onTransparencyValueChanged()));
- connect(aTransparencyWidget, SIGNAL(previewStateChanged()),
- this, SLOT(onPreviewStateChanged()));
aDlg->setContent(aTransparencyWidget);
aTransparencyWidget->setValue(aCurrentValue);
QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
aMgr->startOperation(aDescription.toStdString());
- aDlg->move(QCursor::pos());
- bool isDone = aDlg->exec() == QDialog::Accepted;
- if (!isDone)
- return;
-
- // 4. set the value to all results
- aCurrentValue = aTransparencyWidget->getValue();
- setTransparency(aCurrentValue, theObjects);
+ if (aDlg->exec() == QDialog::Accepted) {
+ // 4. set the value to all results
+ aCurrentValue = aTransparencyWidget->getValue();
+ setTransparency(aCurrentValue, theObjects);
+ aMgr->finishOperation();
+ } else {
+ aMgr->abortOperation();
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ }
- aMgr->finishOperation();
updateCommandStatus();
}
void XGUI_Workshop::onTransparencyValueChanged()
{
XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
- if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
- return;
-
- QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
- setTransparency(aTransparencyWidget->getValue(), anObjects);
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-}
-
-//**************************************************************
-void XGUI_Workshop::onPreviewStateChanged()
-{
- XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
- if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
+ if (!aTransparencyWidget)
return;
QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
}
-//**************************************************************
-#define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
-for (int i = 0; i < aDoc->size(aGroupName); i++) { \
- aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
-}
//******************************************************
void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
}
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
myObjectBrowser->updateAllIndexes();
+
+ updateColorScaleVisibility();
}
//**************************************************************
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
#endif
std::set<ObjectPtr> anObjects;
- foreach (ObjectPtr aObj, theList) {
+ foreach (ObjectPtr aObj, aSrcList) {
anObjects.insert(aObj);
}
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));
// Necessary for update icons in ObjectBrowser on Linux
myObjectBrowser->updateAllIndexes();
+ updateColorScaleVisibility();
+}
+
+
+//**************************************************************
+void XGUI_Workshop::updateColorScaleVisibility()
+{
+ QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+ viewer()->setColorScaleShown(false);
+ if (aObjects.size() == 1) {
+ FieldStepPtr aStep =
+ std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObjects.first());
+ if (aStep.get() && myDisplayer->isVisible(aStep)) {
+ AISObjectPtr aAisPtr = myDisplayer->getAISObject(aStep);
+ Handle(AIS_InteractiveObject) aIO = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
+ ModuleBase_IStepPrs* aPrs = dynamic_cast<ModuleBase_IStepPrs*>(aIO.get());
+ if (aPrs) {
+ ModelAPI_AttributeTables::ValueType aType = aPrs->dataType();
+ if ((aType == ModelAPI_AttributeTables::DOUBLE) ||
+ (aType == ModelAPI_AttributeTables::INTEGER) ||
+ (aType == ModelAPI_AttributeTables::BOOLEAN)) {
+ myViewerProxy->setupColorScale();
+ if (aType == ModelAPI_AttributeTables::BOOLEAN) {
+ myViewerProxy->setColorScaleIntervals(2);
+ myViewerProxy->setColorScaleRange(0., 1.);
+ }
+ else {
+ double aMin, aMax;
+ aPrs->dataRange(aMin, aMax);
+ myViewerProxy->setColorScaleRange(aMin, aMax);
+ }
+ myViewerProxy->setColorScaleTitle(aStep->name().c_str());
+ myViewerProxy->setColorScaleShown(true);
+ }
+ }
+ }
+ }
+}
+
+
+//**************************************************************
+void XGUI_Workshop::setNormalView(bool toInvert)
+{
+ QList<ModuleBase_ViewerPrsPtr> aPrsList =
+ mySelector->selection()->getSelected(ModuleBase_ISelection::Viewer);
+ GeomShapePtr aPlanarFace;
+ foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
+ GeomShapePtr aShape = aPrs->shape();
+ if (aShape.get() && aShape->isPlanar()) {
+ aPlanarFace = aShape;
+ break;
+ }
+ }
+ if (aPlanarFace.get()) {
+ GeomFacePtr aFace(new GeomAPI_Face(aPlanarFace));
+ GeomPlanePtr aPlane = aFace->getPlane();
+ GeomDirPtr aNormal = aPlane->direction();
+ if (toInvert)
+ aNormal->reverse();
+ GeomPointPtr aPos = aPlane->location();
+
+ double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
+ aFace->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+
+ Handle(V3d_View) aView = myViewerProxy->activeView();
+ double aScale = aView->Scale();
+ aView->SetAt(aPos->x(), aPos->y(), aPos->z());
+ aView->SetProj(aNormal->x(), aNormal->y(), aNormal->z());
+ Bnd_Box aBox;
+ aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+ aView->FitAll(aBox);
+ }
}
//**************************************************************
ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
continue;
- myDisplayer->display(aObj, false);
+ ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
+ if (aResBody.get())
+ synchronizeResultTree(aResBody, false);
+ else
+ myDisplayer->display(aObj, false);
}
}
if (theUpdateViewer)
myDisplayer->updateViewer();
}
+
+void XGUI_Workshop::synchronizeResultTree(const ResultBodyPtr& theRes, bool theUpdateViewer)
+{
+ if (theRes->numberOfSubs() > 0)
+ for (int i = 0; i < theRes->numberOfSubs(); i++) {
+ ResultBodyPtr aRes = theRes->subResult(i);
+ if (aRes.get())
+ synchronizeResultTree(aRes, theUpdateViewer);
+ }
+ else {
+ if (theRes->isDisplayed())
+ myDisplayer->display(theRes, theUpdateViewer);
+ else
+ myDisplayer->erase(theRes, theUpdateViewer);
+ }
+}
#endif
//******************************************************
}
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)
}
if (aSelList.count() > theObjects.count()) {
// if something was found
- bool aBlocked = objectBrowser()->blockSignals(true);
objectBrowser()->setObjectsSelected(aSelList);
- objectBrowser()->blockSignals(aBlocked);
objectBrowser()->ensureVisible(aNewSel.first());
}
}
updateCommandStatus();
}
+
+void XGUI_Workshop::onAutoApply()
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ bool isBlocked = aMgr->isAutoUpdateBlocked();
+ aMgr->blockAutoUpdate(!isBlocked);
+}
+
+void XGUI_Workshop::updateAutoComputeState()
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ bool isComputeBlocked = aMgr->isAutoUpdateBlocked();
+#ifdef HAVE_SALOME
+// QAction* aUpdateCmd;
+// QList<QAction*> 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::clearTemporaryDir()
+{
+ QDir aDir(myTmpDir.path());
+ if (!aDir.isEmpty()) {
+ QStringList aEntries;
+ aDir.entryList(aEntries);
+ foreach(QString aFile, aEntries) {
+ aDir.remove(aFile);
+ }
+ }
+}
+
+
+void XGUI_Workshop::onDockSizeChanged()
+{
+ QDockWidget* aDockWgt = dynamic_cast<QDockWidget*>(myObjectBrowser->parentWidget());
+ int aObWidth = aDockWgt->size().width();
+ if (myPropertyPanel->width() != aObWidth) {
+ QList<QDockWidget*> aWgtList;
+ aWgtList << myPropertyPanel << aDockWgt;
+ QList<int> aSizeList;
+ aSizeList << aObWidth << aObWidth;
+ desktop()->resizeDocks(aWgtList, aSizeList, Qt::Horizontal);
+ disconnect(myObjectBrowser, SIGNAL(sizeChanged()), this, SLOT(onDockSizeChanged()));
+ }
+}
+
+void XGUI_Workshop::deactivateCurrentSelector()
+{
+ myActiveControlMgr->deactivateSelector(myActiveControlMgr->activeSelector());
+}