X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Workshop.cpp;h=b78a019bccde374fcd12c43ef7c647f5f00449fa;hb=b86ed875ca3ab2b1d10a5d4d06a6954820849bed;hp=799f5c00f172d71a5e96d06d435cd5b7b6381204;hpb=845faaf1f35a4054431eb57656ab52b5c1d6655a;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 799f5c00f..b78a019bc 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2020 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 @@ -91,6 +91,7 @@ #include #include #include +#include #include #include @@ -199,17 +200,17 @@ static QString MyImportPartFilter(QObject::tr("Part files (*.shaperpart);;All fi XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) : QObject(), myModule(NULL), - mySalomeConnector(theConnector), + myObjectBrowser(0), myPropertyPanel(0), - myInspectionPanel(0), myFacesPanel(0), - myObjectBrowser(0), - myDisplayer(0) - //myViewerSelMode(TopAbs_FACE) + myDisplayer(0), + mySalomeConnector(theConnector), + //myViewerSelMode(TopAbs_FACE), + myInspectionPanel(0) { mySelector = new XGUI_SelectionMgr(this); myModuleConnector = new XGUI_ModuleConnector(this); - myOperationMgr = new XGUI_OperationMgr(this, 0); + myOperationMgr = new XGUI_OperationMgr(this, myModuleConnector); ModuleBase_IWorkshop* aWorkshop = moduleConnector(); // Has to be defined first in order to get errors and messages from other components myEventsListener = new XGUI_WorkshopListener(this); @@ -272,8 +273,6 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) //connect(myViewerProxy, SIGNAL(selectionChanged()), // myActionsMgr, SLOT(updateOnViewSelection())); - myOperationMgr->setWorkshop(aWorkshop); - myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop); connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)), @@ -472,38 +471,49 @@ void XGUI_Workshop::initMenu() // 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(), - false, "MEN_DESK_FILE"); - connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs())); - - aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."), + // Import sub-menu + aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Part set..."), tr("Import native file"), QIcon(), QKeySequence(), - false, "MEN_DESK_FILE"); + false, "MEN_DESK_FILE", tr("Import"), 10, 10); connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen())); - salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE"); - aAction = salomeConnector()->addDesktopCommand("EXPORT_PART_CMD", tr("Export part..."), - tr("Export a part of the current document into a file"), - QIcon(), QKeySequence(), - false, "MEN_DESK_FILE"); - connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onExportPart())); - - aAction = salomeConnector()->addDesktopCommand("IMPORT_PART_CMD", tr("Import part..."), + aAction = salomeConnector()->addDesktopCommand("IMPORT_PART_CMD", tr("Part..."), tr("Import structure of a part"), QIcon(), QKeySequence(), - false, "MEN_DESK_FILE"); + false, "MEN_DESK_FILE", tr("Import"), 10, 10); connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportPart())); - aAction = salomeConnector()->addDesktopCommand("IMPORT_SHAPE_CMD", tr("Import shape..."), - tr("Import shape from a file"), + aAction = salomeConnector()->addDesktopCommand("IMPORT_SHAPE_CMD", tr("From CAD format..."), + tr("Import shape from a CAD format file"), ModuleBase_IconFactory::loadIcon("icons/Exchange/import.png"), - QKeySequence(), false, "MEN_DESK_FILE"); + QKeySequence(), false, "MEN_DESK_FILE", tr("Import"), 10, 10); connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportShape())); - salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE"); + aAction = salomeConnector()->addDesktopCommand("IMPORT_IMAGE_CMD", tr("Picture..."), + tr("Import a picture from an image file"), + QIcon(), + QKeySequence(), false, "MEN_DESK_FILE", tr("Import"), 10, 10); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportImage())); + + // Export sub-menu + aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Part set..."), + tr("Export the current document into a native file"), + QIcon(), QKeySequence(), + false, "MEN_DESK_FILE", tr("Export"), 10, 11); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs())); + + aAction = salomeConnector()->addDesktopCommand("EXPORT_PART_CMD", tr("Part..."), + tr("Export a part of the current document into a file"), + QIcon(), QKeySequence(), + false, "MEN_DESK_FILE", tr("Export"), 10, 11); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onExportPart())); + + aAction = salomeConnector()->addDesktopCommand("EXPORT_SHAPE_CMD", tr("To CAD format..."), + tr("Export shape to a CAD format file"), + ModuleBase_IconFactory::loadIcon("icons/Exchange/export.png"), + QKeySequence(), false, "MEN_DESK_FILE", tr("Export"), 10, 11); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onExportShape())); #else // File commands group @@ -589,13 +599,11 @@ void XGUI_Workshop::onStartWaiting() //****************************************************** void XGUI_Workshop::onAcceptActionClicked() { - QAction* anAction = dynamic_cast(sender()); XGUI_OperationMgr* anOperationMgr = operationMgr(); if (anOperationMgr) { ModuleBase_OperationFeature* aFOperation = dynamic_cast (anOperationMgr->currentOperation()); if (aFOperation) { - //if (errorMgr()->canProcessClick(anAction, aFOperation->feature())) myOperationMgr->commitOperation(); } } @@ -604,7 +612,6 @@ void XGUI_Workshop::onAcceptActionClicked() //****************************************************** void XGUI_Workshop::onAcceptPlusActionClicked() { - QAction* anAction = dynamic_cast(sender()); XGUI_OperationMgr* anOperationMgr = operationMgr(); if (anOperationMgr) { ModuleBase_OperationFeature* aFOperation = dynamic_cast @@ -633,16 +640,22 @@ void XGUI_Workshop::onPreviewActionClicked() //****************************************************** -void XGUI_Workshop::onHelpActionClicked() +void XGUI_Workshop::onHelpActionClicked() const { XGUI_OperationMgr* anOperationMgr = operationMgr(); if (anOperationMgr) { ModuleBase_Operation* aOperation = anOperationMgr->currentOperation(); if (aOperation) { - QString aHelpPage = aOperation->helpFileName(); - if (!aHelpPage.isEmpty()) { - QString aDocDir; - const QChar aSep = QDir::separator(); + showHelpPage(aOperation->helpFileName()); + } + } +} + +void XGUI_Workshop::showHelpPage(const QString& thePage) const +{ + if (!thePage.isEmpty()) { + QString aDocDir; + const QChar aSep = QDir::separator(); // QString platform; // SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr(); //#ifdef WIN32 @@ -653,21 +666,19 @@ void XGUI_Workshop::onHelpActionClicked() // QString aBrowserName = aResMgr->stringValue("ExternalBrowser", platform); #ifdef HAVE_SALOME - QString aDir(getenv("SHAPER_ROOT_DIR")); - if (!aDir.isEmpty()) { - aDocDir = aDir + aSep + "share" + aSep + "doc" + aSep + - "salome" + aSep + "gui" + aSep + "SHAPER"; - } + QString aDir(getenv("SHAPER_ROOT_DIR")); + if (!aDir.isEmpty()) { + aDocDir = aDir + aSep + "share" + aSep + "doc" + aSep + + "salome" + aSep + "gui" + aSep + "SHAPER"; + } #else - QString aDir(getenv("CADBUILDER_ROOT_DIR")); - aDocDir = aDir + aSep + "doc" + aSep + "gui"; + QString aDir(getenv("CADBUILDER_ROOT_DIR")); + aDocDir = aDir + aSep + "doc" + aSep + "gui"; #endif - QString aFileName = aDocDir + aSep + aHelpPage; - if (QFile::exists(aFileName)) { - QUrl aUrl = QUrl::fromLocalFile(aFileName); - QDesktopServices::openUrl(aUrl); - } - } + QString aFileName = aDocDir + aSep + thePage; + if (QFile::exists(aFileName)) { + QUrl aUrl = QUrl::fromLocalFile(aFileName); + QDesktopServices::openUrl(aUrl); } } } @@ -1034,8 +1045,6 @@ void XGUI_Workshop::openFile(const QString& theDirectory) #ifdef _DEBUG bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start"); if (aNewPart) { - - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); int aSize = aRootDoc->size(ModelAPI_ResultPart::group()); if (aSize > 0 ) { ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0); @@ -1209,20 +1218,32 @@ void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, i if (anActiveWidget->processAction(theActionType, aParam)) return; } + else + { + XGUI_FacesPanel * anFacePannel = facesPanel(); + if(ActionUndo == theActionType && anFacePannel->isActivePanel()) + { + anFacePannel->processUndo(); + return; + } + } // the viewer update should be blocked in order to avoid the features blinking. For the created // feature a results are created, the flush of the created signal caused the viewer redisplay for // each created result. After a redisplay signal is flushed. So, the viewer update is blocked // until redo of all possible objects happens bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false); + int aTimes = theTimes; SessionPtr aMgr = ModelAPI_Session::get(); if (aMgr->isOperation()) { XGUI_OperationMgr* aOpMgr = operationMgr(); /// this is important for nested operations /// when sketch operation is active, this condition is false and /// the sketch operation is not aborted - if (aOpMgr->canStopOperation(aOpMgr->currentOperation())) + if (aOpMgr->canStopOperation(aOpMgr->currentOperation())) { aOpMgr->abortOperation(aOpMgr->currentOperation()); + aTimes--; + } else { myDisplayer->enableUpdateViewer(isUpdateEnabled); @@ -1233,7 +1254,7 @@ void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, i std::list anActionList = theActionType == ActionUndo ? aMgr->undoList() : aMgr->redoList(); std::list::const_iterator aIt = anActionList.cbegin(); - for (int i = 0; (i < theTimes) && (aIt != anActionList.cend()); ++i, ++aIt) { + for (int i = 0; (i < aTimes) && (aIt != anActionList.cend()); ++i, ++aIt) { if (theActionType == ActionUndo) aMgr->undo(); else @@ -1305,6 +1326,8 @@ void XGUI_Workshop::onImportPart() if (abortAllOperations()) { ModuleBase_OperationFeature* anImportPartOp = dynamic_cast( module()->createOperation(ExchangePlugin_ImportPart::ID())); + anImportPartOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() + + "importFeature.html"); myPropertyPanel->updateApplyPlusButton(anImportPartOp->feature()); operationMgr()->startOperation(anImportPartOp); } @@ -1316,17 +1339,47 @@ void XGUI_Workshop::onImportShape() if (abortAllOperations()) { ModuleBase_OperationFeature* anImportOp = dynamic_cast( module()->createOperation(ExchangePlugin_Import::ID())); + anImportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() + + "importFeature.html"); + myPropertyPanel->updateApplyPlusButton(anImportOp->feature()); + operationMgr()->startOperation(anImportOp); + } +} + +//****************************************************** +void XGUI_Workshop::onImportImage() +{ + if (abortAllOperations()) { + ModuleBase_OperationFeature* anImportOp = dynamic_cast( + module()->createOperation(ExchangePlugin_Import_Image::ID())); + anImportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() + + "importFeature.html"); myPropertyPanel->updateApplyPlusButton(anImportOp->feature()); operationMgr()->startOperation(anImportOp); } } +//****************************************************** +void XGUI_Workshop::onExportShape() +{ + if (abortAllOperations()) { + ModuleBase_OperationFeature* anExportOp = dynamic_cast( + module()->createOperation(ExchangePlugin_ExportFeature::ID())); + anExportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() + + "exportFeature.html"); + myPropertyPanel->updateApplyPlusButton(anExportOp->feature()); + operationMgr()->startOperation(anExportOp); + } +} + //****************************************************** void XGUI_Workshop::onExportPart() { if (abortAllOperations()) { ModuleBase_OperationFeature* anExportPartOp = dynamic_cast( module()->createOperation(ExchangePlugin_ExportPart::ID())); + anExportPartOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() + + "exportFeature.html"); myPropertyPanel->updateApplyPlusButton(anExportPartOp->feature()); operationMgr()->startOperation(anExportPartOp); } @@ -1681,6 +1734,15 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) changeColor(aObjects); else if (theId == "ISOLINES_CMD") changeIsoLines(aObjects); + else if (theId == "SHOW_ISOLINES_CMD") { + foreach(ObjectPtr aObj, aObjects) { + ResultPtr aResult = std::dynamic_pointer_cast(aObj); + if (aResult.get()) + ModelAPI_Tools::showIsoLines(aResult, !ModelAPI_Tools::isShownIsoLines(aResult)); + } + mySelector->clearSelection(); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } else if (theId == "DEFLECTION_CMD") changeDeflection(aObjects); else if (theId == "TRANSPARENCY_CMD") @@ -1865,7 +1927,7 @@ bool XGUI_Workshop::prepareForDisplay(const std::set& theObjects) con if (!facesPanel()->isObjectHiddenByPanel(*anObjectsIt)) continue; aHiddenObjects.insert(*anObjectsIt); - aHiddenObjectNames.append((*anObjectsIt)->data()->name().c_str()); + aHiddenObjectNames.append(QString::fromStdWString((*anObjectsIt)->data()->name())); } if (aHiddenObjects.empty()) // in parameter objects there are no hidden objects in hide face return true; @@ -1920,7 +1982,7 @@ void XGUI_Workshop::deleteObjects() ResultConstructionPtr aConstr = std::dynamic_pointer_cast(aObj); FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); if (aFeature) { - notDelete = (!aFeature->isInHistory()) && aConstr->isInfinite(); + notDelete = (!aFeature->isInHistory()) && (aConstr && aConstr->isInfinite()); if (notDelete) { anObjects.removeAll(aObj); aIt--; @@ -2071,7 +2133,7 @@ void XGUI_Workshop::cleanHistory() if (!anUnusedObjects.empty()) { QStringList aNames; foreach (const FeaturePtr& aFeature, anUnusedObjects) { - aNames.append(aFeature->name().c_str()); + aNames.append(QString::fromStdWString(aFeature->name())); } aNames.sort(); QString anUnusedNames = aNames.join(", "); @@ -2224,8 +2286,8 @@ std::list allFeatures(const DocumentPtr& theDocument) std::dynamic_pointer_cast(aResult); if (aResultPart.get() && aResultPart->partDoc().get()) { // Recursion - std::list anAllFeatures = allFeatures(aResultPart->partDoc()); - aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end()); + std::list aPartFeatures = allFeatures(aResultPart->partDoc()); + aResultList.insert(aResultList.end(), aPartFeatures.begin(), aPartFeatures.end()); } } @@ -2734,7 +2796,7 @@ void XGUI_Workshop::updateColorScaleVisibility() aPrs->dataRange(aMin, aMax); myViewerProxy->setColorScaleRange(aMin, aMax); } - myViewerProxy->setColorScaleTitle(aStep->name().c_str()); + myViewerProxy->setColorScaleTitle(QString::fromStdWString(aStep->name())); myViewerProxy->setColorScaleShown(true); } } @@ -2751,7 +2813,7 @@ void XGUI_Workshop::setNormalView(bool toInvert) GeomShapePtr aPlanarFace; foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) { GeomShapePtr aShape = aPrs->shape(); - if (aShape.get() && aShape->isPlanar()) { + if (aShape.get() && aShape->isFace() && aShape->isPlanar()) { aPlanarFace = aShape; break; } @@ -2768,7 +2830,6 @@ void XGUI_Workshop::setNormalView(bool toInvert) 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; @@ -2781,7 +2842,7 @@ void XGUI_Workshop::setNormalView(bool toInvert) void XGUI_Workshop::registerValidators() const { SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + MAYBE_UNUSED ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); } //************************************************************** @@ -3105,12 +3166,12 @@ void XGUI_Workshop::onAutoApply() SessionPtr aMgr = ModelAPI_Session::get(); bool isBlocked = aMgr->isAutoUpdateBlocked(); aMgr->blockAutoUpdate(!isBlocked); + myDisplayer->updateViewer(); } void XGUI_Workshop::updateAutoComputeState() { SessionPtr aMgr = ModelAPI_Session::get(); - bool isComputeBlocked = aMgr->isAutoUpdateBlocked(); #ifdef HAVE_SALOME // QAction* aUpdateCmd; // QList aCommands = mySalomeConnector->commandList(); @@ -3123,6 +3184,7 @@ void XGUI_Workshop::updateAutoComputeState() // aUpdateCmd->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") : // QIcon(":pictures/autoapply_start.png")); #else + bool isComputeBlocked = aMgr->isAutoUpdateBlocked(); AppElements_MainMenu* aMenuBar = myMainWindow->menuObject(); AppElements_Command* aUpdateCmd = aMenuBar->feature("AUTOCOMPUTE_CMD"); aUpdateCmd->button()->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") : @@ -3168,11 +3230,20 @@ void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects) if (theObjects.isEmpty()) return; - std::vector aValues; - if (theObjects.size() == 1) { - ResultPtr aRes = std::dynamic_pointer_cast(theObjects.first()); + QList aResultList; + ResultPtr aRes; + foreach(ObjectPtr aObj, theObjects) { + aRes = std::dynamic_pointer_cast(aObj); if (aRes.get()) - ModelAPI_Tools::getIsoLines(aRes, aValues); + aResultList.append(aRes); + } + + std::vector aValues; + bool isVisible; + if (aResultList.size() == 1) { + ResultPtr aResult = aResultList.first(); + if (aResult.get()) + ModelAPI_Tools::getIsoLines(aResult, isVisible, aValues); else return; } @@ -3184,9 +3255,13 @@ void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects) if (!abortAllOperations()) return; - QDialog aDlg; + XGUI_PropertyDialog aDlg(desktop()); aDlg.setWindowTitle(tr("Number of Iso-lines")); - QFormLayout* aLayout = new QFormLayout(&aDlg); + + QWidget* aIsosWgt = new QWidget(&aDlg); + QFormLayout* aLayout = new QFormLayout(aIsosWgt); + ModuleBase_Tools::adjustMargins(aLayout); + aDlg.setContent(aIsosWgt); QSpinBox* aUNb = new QSpinBox(&aDlg); aUNb->setValue(aValues[0]); @@ -3196,12 +3271,6 @@ void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects) aVNb->setValue(aValues[1]); aLayout->addRow("V:", aVNb); - QDialogButtonBox* aButtons = - new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &aDlg); - connect(aButtons, SIGNAL(accepted()), &aDlg, SLOT(accept())); - connect(aButtons, SIGNAL(rejected()), &aDlg, SLOT(reject())); - aLayout->addRow(aButtons); - if (aDlg.exec() == QDialog::Accepted) { SessionPtr aMgr = ModelAPI_Session::get(); QString aDescription = contextMenuMgr()->action("ISOLINES_CMD")->text(); @@ -3209,15 +3278,12 @@ void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects) aValues[0] = aUNb->value(); aValues[1] = aVNb->value(); - ResultPtr aRes; - foreach(ObjectPtr aObj, theObjects) { - aRes = std::dynamic_pointer_cast(aObj); - if (aRes.get()) { - ModelAPI_Tools::setIsoLines(aRes, aValues); - } + foreach(ResultPtr aResult, aResultList) { + ModelAPI_Tools::setIsoLines(aResult, aValues); } + mySelector->clearSelection(); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); aMgr->finishOperation(); updateCommandStatus(); } -} \ No newline at end of file +}