X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCalc%2Fgui%2FPresentationController.cxx;h=77b517613178d58d8d59bff45360c16f376058c7;hb=e53aa1a324e0744debffac6d2aa66171c47aef69;hp=ffd9bab25867669160df4cd6d93aeaed4afd0bda;hpb=ede17e79573b8cbb9a384e698a925450cc386a89;p=modules%2Fmed.git diff --git a/src/MEDCalc/gui/PresentationController.cxx b/src/MEDCalc/gui/PresentationController.cxx index ffd9bab25..77b517613 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -31,16 +31,25 @@ #include "MEDPresentationScalarMap.hxx" #include "MEDPresentationContour.hxx" #include "MEDPresentationSlices.hxx" +#include "MEDPresentationPointSprite.hxx" +#include "MEDPresentationVectorField.hxx" +#include "MEDPresentationDeflectionShape.hxx" #include "MEDWidgetHelperMeshView.hxx" #include "MEDWidgetHelperScalarMap.hxx" #include "MEDWidgetHelperContour.hxx" #include "MEDWidgetHelperSlices.hxx" +#include "MEDWidgetHelperPointSprite.hxx" +#include "MEDWidgetHelperVectorField.hxx" +#include "MEDWidgetHelperDeflectionShape.hxx" #include #include #include +#include +#include + #include #include @@ -101,21 +110,6 @@ PresentationController::~PresentationController() delete((*it).second); } -/** - * [ABN] Created this probably because I don't know the right way to deal with non existent - * attributes in an object from the study ... - */ -int -PresentationController::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char * name) -{ - int theInt = -1; - try { - theInt = _studyEditor->getParameterInt(obj,name); - } - catch(...) { } - return theInt; -} - std::string PresentationController::_getIconName(const std::string& name) { @@ -172,7 +166,7 @@ PresentationController::createActions() // Presentations int presentationToolbarId = _salomeModule->createTool("Presentations", "PresentationToolbar"); - int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, 1); + int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, -1, 10); label = tr("LAB_PRESENTATION_MESH_VIEW"); tooltip = tr("TIP_PRESENTATION_MESH_VIEW"); @@ -236,21 +230,21 @@ PresentationController::createActions() label = tr("LAB_DELETE_PRESENTATION"); tooltip = tr("TIP_DELETE_PRESENTATION"); - icon = tr(_getIconName("ICO_DELETE_PRESENTATION").c_str()); + icon = tr("ICO_DELETE_PRESENTATION"); actionId = _salomeModule->createStandardAction(label,this, SLOT(onDeletePresentation()),icon,tooltip); // _salomeModule->createTool(actionId, presentationToolbarId); // _salomeModule->action(actionId)->setIconVisibleInMenu(true); _salomeModule->createMenu(actionId, presentationMenuId); - // - // Actions for popup menu only - // // Low level PARAVIS dump label = tr("LAB_PARAVIS_DUMP"); - //icon = tr("ICO_DATASOURCE_EXPAND_FIELD"); + tooltip = tr("TIP_PARAVIS_DUMP"); actionId = _salomeModule->createStandardAction(label,this,SLOT(onParavisDump()),""); - _salomeModule->addActionInPopupMenu(actionId); + _salomeModule->createMenu(actionId, presentationMenuId); + // + // Actions for popup menu only + // } @@ -299,34 +293,54 @@ PresentationController::visualize(PresentationEvent::EventType eventType) // visualisation using the tui command (so that the user can see how // to make a view of an object from the tui console). for (int i=0; isize(); i++) { - SALOMEDS::SObject_var soField = listOfSObject->at(i); - int fieldId = getIntParamFromStudyEditor(soField, FIELD_ID); - if (fieldId < 0) // is it a field serie ? + SALOMEDS::SObject_var soObj = listOfSObject->at(i); + std::string name(_studyEditor->getName(soObj)); + if (soObj->_is_nil() || name == "MEDCalc") + return; + + int fieldId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_ID); + int meshId = _salomeModule->getIntParamFromStudyEditor(soObj, MESH_ID); + MEDCALC::FieldHandler* fieldHandler = 0; + MEDCALC::MeshHandler* meshHandler = 0; + + // is it a mesh? + if (meshId >= 0) { - int fieldSeriesId = getIntParamFromStudyEditor(soField, FIELD_SERIES_ID); - // If fieldId and fieldSeriesId equals -1, then it means that it is not a field - // managed by the MED module, and we stop this function process. - if ( fieldSeriesId < 0) + if (eventType != PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW) continue; - MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId); - if (fieldHandlerList->length() < 0) - continue; - // For a field series, get the first real field entry: - MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0]; - fieldId = fieldHandler.id; + meshHandler = MEDFactoryClient::getDataManager()->getMeshHandler(meshId); + } + else + { + if (fieldId < 0) // is it a field series? + { + int fieldSeriesId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID); + // If fieldId and fieldSeriesId equals -1, then it means that it is not a field + // managed by the MED module, and we stop this function process. + if ( fieldSeriesId < 0) + continue; + + MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId); + if (fieldHandlerList->length() < 0) + continue; + // For a field series, get the first real field entry: + MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0]; + fieldId = fieldHandler.id; + } + fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId); } - MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId); - if (! fieldHandler) { + if ((!fieldHandler) && (!meshHandler)) { QMessageBox::warning(_salomeModule->getApp()->desktop(), tr("Operation not allowed"), - tr("No field is defined")); + tr("No field (or mesh) is defined")); return; } PresentationEvent* event = new PresentationEvent(); event->eventtype = eventType; event->fieldHandler = fieldHandler; + event->meshHandler = meshHandler; emit presentationSignal(event); // --> processPresentationEvent() } } @@ -385,7 +399,10 @@ PresentationController::onDeletePresentation() // For each object, emit a signal to the workspace to request pres deletion for (int i=0; isize(); i++) { SALOMEDS::SObject_var soPres = listOfSObject->at(i); - int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID); + std::string name(_studyEditor->getName(soPres)); + if (soPres->_is_nil() || name == "MEDCalc") + return; + int presId = _salomeModule->getIntParamFromStudyEditor(soPres,PRESENTATION_ID); // If fieldId equals -1, then it means that it is not a field // managed by the MED module, and we stop this function process. if ( presId < 0 ) @@ -478,9 +495,15 @@ PresentationController::processPresentationEvent(const PresentationEvent* event) QString scalarBarRange = getScalarBarRangePython(); MEDCALC::FieldHandler* fieldHandler = event->fieldHandler; QStringList commands; + + // [ABN] using event mechanism for all this is awkward? TODO: direct implementation in each + // dedicated widget helper class? + if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW ) { - commands += QString("presentation_id = medcalc.MakeMeshView(accessField(%1), viewMode=%2)").arg(fieldHandler->id).arg(viewMode); - commands += QString("presentation_id"); + // Do we request mesh view from a field or from a mesh only? + int meshId = event->meshHandler ? event->meshHandler->id : event->fieldHandler->meshid; + commands += QString("presentation_id = medcalc.MakeMeshView(%1, viewMode=%2)").arg(meshId).arg(viewMode); + commands += QString("presentation_id"); } else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) { commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") @@ -489,29 +512,31 @@ PresentationController::processPresentationEvent(const PresentationEvent* event) } else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) { commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") - .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); commands += QString("presentation_id"); } - // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) { - // commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); - // commands += QString("presentation_id"); - // } - else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) { + else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) { commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") - .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); commands += QString("presentation_id"); - } - // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) { - // commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); - // commands += QString("presentation_id"); - // } - // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) { - // commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); - // commands += QString("presentation_id"); - // } - - // [ABN] using event mechanism for this is awkward? TODO: direct implementation in each - // dedicated widget helper class? + } + else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) { + commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + commands += QString("presentation_id"); + } + else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) { + commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + commands += QString("presentation_id"); + } + else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) { + commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + commands += QString("presentation_id"); + } + + else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) { std::string typ = getPresTypeFromWidgetHelper(event->presentationId); commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId); @@ -571,7 +596,7 @@ PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager std::map::const_iterator it =_presHelperMap.find(presId); if (it != _presHelperMap.end()) return (*it).second; - MEDWidgetHelper * wh; + MEDWidgetHelper * wh = 0; if (type == MEDPresentationMeshView::TYPE_NAME) wh = new MEDWidgetHelperMeshView(this, _presManager, presId, name, _widgetPresentationParameters); else if (type == MEDPresentationScalarMap::TYPE_NAME) @@ -579,10 +604,18 @@ PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager else if (type == MEDPresentationContour::TYPE_NAME) wh = new MEDWidgetHelperContour(this, _presManager, presId, name, _widgetPresentationParameters); else if (type == MEDPresentationSlices::TYPE_NAME) - wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters); + wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters); + else if (type == MEDPresentationVectorField::TYPE_NAME) + wh = new MEDWidgetHelperVectorField(this, _presManager, presId, name, _widgetPresentationParameters); + else if (type == MEDPresentationPointSprite::TYPE_NAME) + wh = new MEDWidgetHelperPointSprite(this, _presManager, presId, name, _widgetPresentationParameters); + else if (type == MEDPresentationDeflectionShape::TYPE_NAME) + wh = new MEDWidgetHelperDeflectionShape(this, _presManager, presId, name, _widgetPresentationParameters); else { - STDLOG("findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!"); + const char * msg ="findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!"; + STDLOG(msg); + return wh; } _presHelperMap[presId] = wh; return wh; @@ -602,11 +635,13 @@ PresentationController::onPresentationSelected(int presId, const QString& presTy } else { + if(_currentWidgetHelper) + _currentWidgetHelper->releaseWidget(); // Activate corresponding ParaView render view _presManager->activateView(presId); // Update widgets parameters _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString()); - _currentWidgetHelper->udpateWidget(); + _currentWidgetHelper->updateWidget(true); } } @@ -622,23 +657,26 @@ PresentationController::onParavisDump() // For the first object only, request the dump for (int i=0; isize(); i++) { SALOMEDS::SObject_var soPres = listOfSObject->at(i); - int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID); + std::string name(_studyEditor->getName(soPres)); + if (soPres->_is_nil() || name == "MEDCalc") + return; + int presId = _salomeModule->getIntParamFromStudyEditor(soPres,PRESENTATION_ID); // If fieldId equals -1, then it means that it is not a field // managed by the MED module, and we stop this function process. if ( presId < 0 ) continue; std::string dump(_presManager->getParavisDump(presId)); - std::cerr << "#====== ParaVis dump =============== " << std::endl; + std::cerr << "#====== ParaVis dump (presentation " << presId << ") =====" << std::endl; std::cerr << dump; - std::cerr << "#====== End of ParaVis dump ======== " << std::endl; + std::cerr << "#====== End of ParaVis dump =============== " << std::endl; break; // stop at the first one } } void -PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId) +PresentationController::updateTreeViewWithNewPresentation(long dataId, long presentationId) { if (presentationId < 0) { std::cerr << "Unknown presentation\n"; @@ -659,37 +697,36 @@ PresentationController::updateTreeViewWithNewPresentation(long fieldId, long pre SalomeApp_Study* study = dynamic_cast(_salomeModule->application()->activeStudy()); _PTR(Study) studyDS = study->studyDS(); - _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, - oss.str().c_str(), type.c_str(),ico.c_str(), presentationId); - - - // MEDCALC::ViewModeType viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId); - // - // // Remove sibling presentations if view mode is set to REPLACE - // if (viewMode == MEDCALC::VIEW_MODE_REPLACE) { - // MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId); - // CORBA::ULong size = presList->length(); - // - // std::stringstream sstm; - // sstm << "Removing sibling presentation(s): "; - // for (int i = 0; i < size; ++i) - // sstm << (*presList)[i] << " "; - // STDLOG(sstm.str()); - // - // for (int i = 0; i < size; ++i) { - // PresentationEvent* event = new PresentationEvent(); - // event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION; - // XmedDataObject* dataObject = new XmedDataObject(); - // dataObject->setPresentationId((*presList)[i]); - // event->objectdata = dataObject; - // emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent - // } - // - // delete presList; - // } + // Mesh views are always registered at the mesh level: + if (type == MEDPresentationMeshView::TYPE_NAME) + { + _salomeModule->engine()->registerPresentationMesh(_CAST(Study, studyDS)->GetStudy(), dataId, + oss.str().c_str(), type.c_str(),ico.c_str(), presentationId); + } + else + _salomeModule->engine()->registerPresentationField(_CAST(Study, studyDS)->GetStudy(), dataId, + oss.str().c_str(), type.c_str(),ico.c_str(), presentationId); // update Object browser _salomeModule->getApp()->updateObjectBrowser(true); + + // auto-select new presentation + std::string entry = _salomeModule->engine()->getStudyPresentationEntry(_CAST(Study, studyDS)->GetStudy(), presentationId); + SALOME_ListIO selectedObjects; + LightApp_Study* lightStudy = dynamic_cast( _salomeModule->application()->activeStudy() ); + QString component = lightStudy->componentDataType( entry.c_str() ); + selectedObjects.Append( new SALOME_InteractiveObject( (const char*)entry.c_str(), + (const char*)component.toLatin1(), + ""/*refobj->Name().c_str()*/ ) ); + //QStringList selectedObjects; + //selectedObjects << QString(entry.c_str()); + LightApp_SelectionMgr* aSelectionMgr = _salomeModule->getApp()->selectionMgr(); + aSelectionMgr->setSelectedObjects(selectedObjects, false); + + // emit onPresentationSelected + int presId = -1; + _salomeModule->itemClickGeneric(name, type, presId); + onPresentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name)); } void @@ -709,32 +746,53 @@ PresentationController::updateTreeViewForPresentationRemoval(long presentationId _salomeModule->getApp()->updateObjectBrowser(true); } +void +PresentationController::_dealWithReplaceMode() +{ + // Deal with replace mode: presentations with invalid IDs have to be removed: + SalomeApp_Study* study = dynamic_cast(_salomeModule->application()->activeStudy()); + _PTR(Study) studyDS = study->studyDS(); + + MEDCALC::PresentationsList * lstManager = _presManager->getAllPresentations(); + MED_ORB::PresentationsList * lstModule = _salomeModule->engine()->getStudyPresentations(_CAST(Study, studyDS)->GetStudy()); + // The IDs not in the intersection needs deletion: + CORBA::Long * last = lstManager->get_buffer() + lstManager->length(); + for (unsigned i = 0; i < lstModule->length(); i++) { + CORBA::Long * ptr = std::find(lstManager->get_buffer(), last, (*lstModule)[i]); + if (ptr == last) { + STDLOG("Removing pres " << (*lstModule)[i] << " from OB."); + // Presentation in module but not in manager anymore: to be deleted from OB: + updateTreeViewForPresentationRemoval((*lstModule)[i]); + } + } +} + void PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event) { if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) { - updateTreeViewWithNewPresentation(event->dataId, event->presentationId); - // Deal with replace mode: presentations with invalid IDs have to be removed: - SalomeApp_Study* study = dynamic_cast(_salomeModule->application()->activeStudy()); - _PTR(Study) studyDS = study->studyDS(); - - MEDCALC::PresentationsList * lstManager = _presManager->getAllPresentations(); - MED_ORB::PresentationsList * lstModule = _salomeModule->engine()->getStudyPresentations(_CAST(Study, studyDS)->GetStudy()); - // The IDs not in the intersection needs deletion: - CORBA::Long * last = lstManager->get_buffer() + lstManager->length(); - for (unsigned i = 0; i < lstModule->length(); i++) - { - CORBA::Long * ptr = std::find(lstManager->get_buffer(), last, (*lstModule)[i]); - if (ptr == last) - { - STDLOG("Removing pres " << (*lstModule)[i] << " from OB."); - // Presentation in module but not in manager anymore: to be deleted from OB: - updateTreeViewForPresentationRemoval((*lstModule)[i]); - } - } + if (event->dataId == -1) { + // A file has been loaded, and we want to create a default presentation (MeshView) for it + QString viewMode = getViewModePython(); + QStringList commands; + commands += QString("presentation_id = medcalc.MakeMeshView(medcalc.GetFirstMeshFromDataSource(source_id), viewMode=%1)").arg(viewMode); + commands += QString("presentation_id"); + _consoleDriver->exec(commands); + } + else { + updateTreeViewWithNewPresentation(event->dataId, event->presentationId); + _dealWithReplaceMode(); + } } else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) { updateTreeViewForPresentationRemoval(event->presentationId); + // Hide parameter widget if necessary: + onPresentationSelected(-1, "", ""); + } + else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) { + // Update parameter widget if shown: + if(_currentWidgetHelper) + _currentWidgetHelper->updateWidget(false); } } @@ -743,4 +801,3 @@ PresentationController::showDockWidgets(bool isVisible) { _dockWidget->setVisible(isVisible); } -