1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SUPERVGUI.cxx
25 // Author : Francis KLOSS
29 #include "SUPERVGUI.h"
31 #include "QAD_Resource.h"
32 #include "QAD_FileDlg.h"
33 #include "QAD_Application.h"
34 #include "QAD_StudyFrame.h"
35 #include "QAD_RightFrame.h"
36 #include "QAD_LeftFrame.h"
37 #include "QAD_ViewFrame.h"
38 #include "QAD_ObjectBrowser.h"
39 #include "QAD_ObjectBrowserItem.h"
40 #include "SALOME_Selection.h"
41 #include "SALOMEGUI_NameDlg.h"
42 #include "Utils_ORB_INIT.hxx"
43 #include "SALOME_ListIteratorOfListIO.hxx"
44 #include "SALOME_InteractiveObject.hxx"
45 #include <qapplication.h>
46 #include "SALOMEGUI_ImportOperation.h"
48 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
51 int SUPERVGUI::factory = 0;
52 SUPERVGUI Supervision("");
55 SUPERVGUI::SUPERVGUI(const QString& theName, QObject* theParent)
56 : SALOMEGUI( theName, theParent ),
62 Trace("SUPERVGUI::SUPERVGUI")
65 MESSAGE("SUPERVGUI Info : factory build");
67 MESSAGE("SUPERVGUI Error : another call to factory constructor");
71 SUPERVGUI::~SUPERVGUI() {
72 Trace("SUPERVGUI::~SUPERVGUI")
75 //if (!engine->_is_nil()) CORBA::release(engine);
78 if (browser->isVisible())
82 MESSAGE("SUPERVGUI Info : factory destroy");
84 MESSAGE("SUPERVGUI Error : another call to factory destructor");
88 void SUPERVGUI::init(QAD_Desktop* parent) {
89 Trace("SUPERVGUI::init")
92 study = desktop->getActiveStudy();
93 SALOME_NamingService* namingService = desktop->getNameService();
94 loadEngine(namingService);
95 browser = new SUPERVGUI_Service(namingService);
96 //info = new SUPERVGUI_Information();
97 cursor = desktop->cursor();
98 connect(desktop->getMainFrame(), SIGNAL(windowActivated(QWidget*)), this, SLOT(setMain(QWidget*)));
101 parent->menuBar()->changeItem(anId,parent->getComponentUserName("SUPERV"));
107 QAD_StudyFrame* SUPERVGUI::createGraph() {
108 QAD_StudyFrame* aStudyFrame = study->newWindow3d(study->getNextStudyFrameName(),
109 VIEW_GRAPHSUPERV, false);
112 SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*)),
114 SLOT(onGraphClosed(QAD_StudyFrame*)));
121 void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) {
122 Trace("SUPERVGUI::loadEngine")
123 SALOME_LifeCycleCORBA LCC(namingService);
124 Engines::Component_var objComponent = LCC.FindOrLoad_Component("SuperVisionContainer", "SUPERV");
125 if (CORBA::is_nil(objComponent)) {
126 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_LOAD_SUPERV"));
130 SUPERV::SuperG_var aSuperVisionComponent;
131 aSuperVisionComponent = SUPERV::SuperG::_narrow(objComponent);
132 if (CORBA::is_nil(aSuperVisionComponent)) {
133 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_NARROW_SUPERV"));
137 // engine = new SUPERV::SuperG_var;
138 engine = aSuperVisionComponent;
141 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
142 Trace("SUPERVGUI::information")
143 return(info->run(node, isReadOnly));
146 void SUPERVGUI::putInfo(const char* mess) {
147 Trace("SUPERVGUI::putInfo")
148 desktop->putInfo(mess);
151 QAD_Desktop* SUPERVGUI::getDesktop() {
152 Trace("SUPERVGUI::getDesktop")
156 SUPERV_Engine SUPERVGUI::getEngine() {
157 Trace("SUPERVGUI::getEngine")
161 SUPERVGUI_Service* SUPERVGUI::getBrowser() {
162 Trace("SUPERVGUI::getBrowser")
166 QCursor SUPERVGUI::getCursor() {
167 Trace("SUPERVGUI::getCursor")
171 SUPERVGUI_Main* SUPERVGUI::getMain() {
172 Trace("SUPERVGUI::getMain")
177 void SUPERVGUI::registerGraph(QString theName, SUPERVGUI_Main* theGraph){
178 theGraph->setHashCode(theName);
179 myGraphList.append(theGraph);
183 void SUPERVGUI::unregisterGraph(SUPERVGUI_Main* theGraph) {
184 SUPERVGUI_Main* aMain;
185 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
186 if (aMain == theGraph)
187 myGraphList.remove(aMain);
192 bool SUPERVGUI::isContains(QAD_Study* theStudy, const QString theKey) {
193 SUPERVGUI_Main* aMain;
194 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
195 if ((aMain->getStudy() == theStudy) && (aMain->getHashCode() == theKey))
202 void SUPERVGUI::onGraphClosed(QAD_StudyFrame* theStudyFrame) {
203 QAD_ViewFrame* viewFrame = theStudyFrame->getRightFrame()->getViewFrame();
204 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
205 disconnect(theStudyFrame, 0 , this, 0);
206 SUPERVGraph_View* view = supervFrame->getViewWidget();
207 SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
209 unregisterGraph(aGraph);
214 void SUPERVGUI::setMain(QWidget* w) {
216 QAD_StudyFrame* aStudyFrame = dynamic_cast<QAD_StudyFrame*>(w);
217 if (!aStudyFrame) return;
219 study = aStudyFrame->getStudy();
222 QAD_ViewFrame* viewFrame = aStudyFrame->getRightFrame()->getViewFrame();
223 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
224 SUPERVGraph_View* view = supervFrame->getViewWidget();
226 main = dynamic_cast<SUPERVGUI_Main*>(view);
228 Trace("SUPERVGUI::setMain - main: "<<main);
232 void SUPERVGUI::importDataflow() {
233 Trace("SUPERVGUI::importDataflow");
234 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
241 if (isContains(study, f)) {
242 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
243 tr("MSG_GRAPH_DISPLAYED").arg(f),
244 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
248 SUPERV_Graph aGraph = engine->StreamGraphE(f);
249 //QFileInfo aFile(f);
250 //aGraph->SetName(aFile.baseName());
251 if (SUPERV_isNull(aGraph)) {
252 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
256 QAD_StudyFrame* aStudyFrame = createGraph();
257 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
258 (aStudyFrame->getRightFrame()->getViewFrame());
260 main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
261 registerGraph(f, main);
262 study->showFrame(aStudyFrame);
267 void SUPERVGUI::displayDataflow() {
268 Trace("SUPERVGUI::displayDataflow");
269 QAD_ObjectBrowser* aBrowser = ((QAD_StudyFrame*)(desktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
270 SUPERV_Graph aDataFlow;
273 QAD_ObjectBrowserItem* item = (QAD_ObjectBrowserItem*)(aBrowser->getListView()->currentItem());
274 SALOMEDS::SObject_var aObj = desktop->getActiveStudy()->getStudyDocument()->FindObjectID(item->getEntry().latin1());
275 SALOMEDS::GenericAttribute_var anAttr;
276 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
277 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
278 Standard_CString ior = anIOR->Value();
280 if (isContains(study, aIORName)) {
281 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
282 tr("MSG_GRAPH_DISPLAYED").arg(""),
283 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
286 aDataFlow = engine->getStreamGraph(ior);
287 if (SUPERV_isNull(aDataFlow)) {
288 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
292 QAD_StudyFrame* aStudyFrame = createGraph();
293 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
294 (aStudyFrame->getRightFrame()->getViewFrame());
296 main = new SUPERVGUI_Main(aViewFrame, desktop, aDataFlow);
297 main->setAsFromStudy(true);
298 registerGraph(aIORName, main);
299 study->showFrame(aStudyFrame);
304 void SUPERVGUI::renameDataflow() {
305 SALOME_Selection* Sel = SALOME_Selection::Selection( study->getSelection() );
306 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
307 for ( ; It.More(); It.Next() ) {
308 Handle(SALOME_InteractiveObject) IObject = It.Value();
310 SALOMEDS::Study_var aStudy = study->getStudyDocument();
311 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
312 SALOMEDS::GenericAttribute_var anAttr;
313 SALOMEDS::AttributeName_var aName;
314 if ( !obj->_is_nil() ) {
315 if (obj->FindAttribute(anAttr, "AttributeName")) {
316 aName = SALOMEDS::AttributeName::_narrow(anAttr);
317 QString nm = QString( aName->Value() );
319 nm = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), nm );
320 if ( !nm.isEmpty() ) {
321 QApplication::setOverrideCursor( Qt::waitCursor );
322 study->renameIObject( IObject, nm );
323 QApplication::restoreOverrideCursor();
331 void SUPERVGUI::exportDataflow() {
332 Trace("SUPERVGUI::exportDataflow")
334 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
336 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
339 tr("TTL_EXPORT_DATAFLOW"),
342 if (main->exportDataflow(f)) {
343 unregisterGraph(main);
344 registerGraph(f, main);
350 void SUPERVGUI::newDataflow() {
351 Trace("SUPERVGUI::editDataflow");
352 QAD_StudyFrame* aStudyFrame = createGraph();
353 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
354 (aStudyFrame->getRightFrame()->getViewFrame());
356 main = new SUPERVGUI_Main(aViewFrame, desktop, false);
358 study->showFrame(aStudyFrame);
362 void SUPERVGUI::modifyDataflow() {
363 Trace("SUPERVGUI::modifyDataflow")
364 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
367 tr("Modify Dataflow"),
370 if (isContains(study, f)) {
371 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
372 tr("MSG_GRAPH_DISPLAYED").arg(f),
373 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
377 SUPERV_Graph aGraph = engine->StreamGraph(f);
379 //aGraph->SetName(aFile.name());
380 if (SUPERV_isNull(aGraph)) {
381 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
385 QAD_StudyFrame* aStudyFrame = createGraph();
386 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
387 (aStudyFrame->getRightFrame()->getViewFrame());
389 main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
390 registerGraph(f, main);
391 study->showFrame(aStudyFrame);
396 void SUPERVGUI::reloadDataflow() {
397 Trace("SUPERVGUI::reloadDataflow")
399 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
405 void SUPERVGUI::runDataflow() {
406 Trace("SUPERVGUI::runDataflow")
408 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
414 void SUPERVGUI::stepByStep() {
415 Trace("SUPERVGUI::stepByStep")
417 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
419 main->startExecute();
423 void SUPERVGUI::killDataflow() {
424 Trace("SUPERVGUI::killDataflow")
426 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
432 void SUPERVGUI::suspendResumeDataflow() {
433 Trace("SUPERVGUI::suspendResumeDataflow")
435 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
437 main->suspendResume();
441 void SUPERVGUI::showComponents() {
442 Trace("SUPERVGUI::showComponents");
444 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
446 if (main->isEditable())
449 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
454 bool SUPERVGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
455 Trace("SUPERVGUI::customPopup");
456 Supervision.init(parent);
457 if(popup->count() > 3) {
458 // Temporary code: is to be deleted soon
459 popup->removeItem(QAD_Display_Popup_ID);
460 popup->removeItem(QAD_DisplayOnly_Popup_ID);
461 popup->removeItem(QAD_Erase_Popup_ID);
462 int id = popup->idAt(popup->count() - 1);
463 if (id < 0 && id != -1) popup->removeItem(id); // separator
464 // Temporary code end
466 SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
467 if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return false;
469 if (Sel->IObjectCount() == 1) {
470 Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject();
472 // insert SUPERV-specific popup items here
474 bool isDataflow, ownObj;
475 whatIsSelected(anIObj, ownObj, isDataflow);
478 popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
479 popup->insertItem("Display", this, SLOT(displayDataflow()));
480 popup->insertSeparator();
483 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
485 if (Sel->IObjectCount() > 1) {
487 SALOME_ListIteratorOfListIO It_forCheckOwner(Sel->StoredIObjects());
488 for(;It_forCheckOwner.More();It_forCheckOwner.Next()) {
489 Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value();
490 bool aIsOwner, aIsDataflow;
491 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
493 if (aIsOwner) aIObjCount++;
495 if (aIObjCount == Sel->IObjectCount()) //all selected objects belong to Supervision
496 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
504 theIsOwner = true if Selected object belongs to Suipervision.
505 theIsDataflow = true if Selected object is Dataflow
507 void SUPERVGUI::whatIsSelected(const Handle(SALOME_InteractiveObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
509 theIsDataflow = false;
511 if (theObj.IsNull()) return;
513 SALOMEDS::Study_var aStudy = study->getStudyDocument();
514 SALOMEDS::SObject_var obj = aStudy->FindObjectID( theObj->getEntry() );
516 if ( !obj->_is_nil() ) {
517 SALOMEDS::SComponent_var comp = obj->GetFatherComponent();
518 if ( !comp->_is_nil() ) {
519 SALOMEDS::GenericAttribute_var anAttr;
520 SALOMEDS::AttributeName_var aName;
521 if (comp->FindAttribute(anAttr, "AttributeName")) {
522 aName = SALOMEDS::AttributeName::_narrow(anAttr);
523 QString compName(aName->Value());
524 //if (compName.compare(STUDY_SUPERVISION) == 0) {
525 if (compName.compare(QAD_Application::getDesktop()->getComponentUserName("SUPERV")) == 0) {
526 SALOMEDS::GenericAttribute_var anAttr;
527 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
528 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
529 SUPERV_Graph aDataFlow = engine->getStreamGraph(anIOR->Value());
530 if (!SUPERV_isNull(aDataFlow))
531 theIsDataflow = true;
533 CORBA::String_var anObjectID = obj->GetID();
534 CORBA::String_var aComponentID = comp->GetID();
535 if (strcmp(anObjectID, aComponentID)) theIsOwner = true;
543 void SUPERVGUI::deleteObject() {
544 SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
545 if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
547 if (QMessageBox::warning(QAD_Application::getDesktop(),
549 tr("MSG_ASK_DELETE"),
551 QMessageBox::Yes) == QMessageBox::No)
554 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
555 for(;It.More();It.Next()) {
556 Handle(SALOME_InteractiveObject) anIObj = It.Value();
557 bool aIsOwner, aIsDataflow;
558 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
560 SALOMEDS::Study_var aStudy = study->getStudyDocument();
561 SALOMEDS::SObject_var aObj = aStudy->FindObjectID( anIObj->getEntry() );
562 if (!aObj->_is_nil()) {
564 SALOMEDS::GenericAttribute_var anAttr;
565 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
566 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
567 QString ior = anIOR->Value();
569 SUPERVGUI_Main* aMain;
570 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
571 if ((aMain->getStudy() == study) && (aMain->getHashCode() == ior)) {
572 aMain->setAsFromStudy(false);
578 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
579 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
581 aBuilder->RemoveObjectWithChildren(aObj);
585 Sel->ClearIObjects() ;
588 bool SUPERVGUI::OnGUIEvent(int command, QAD_Desktop* parent) {
589 Supervision.init(parent);
592 Supervision.importDataflow();
596 Supervision.exportDataflow();
600 Supervision.newDataflow();
604 Supervision.modifyDataflow();
608 Supervision.reloadDataflow();
612 Supervision.runDataflow();
616 Supervision.killDataflow();
620 Supervision.suspendResumeDataflow();
624 Supervision.showComponents();
628 Supervision.stepByStep();
632 QMessageBox::warning(QAD_Application::getDesktop(), "Supervision Error", "Unknown Command From Salome");
637 bool SUPERVGUI::SetSettings(QAD_Desktop* parent) {
638 Trace("SUPERVGUI::SetSettings");
639 Supervision.init(parent);
643 void SUPERVGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject) {
648 bool SUPERVGUI::ActiveStudyChanged(QAD_Desktop* parent) {
649 Trace("SUPERVGUI::activeStudyChanged");
650 study = desktop->getActiveStudy();
654 void SUPERVGUI::SupportedViewType (int* buffer, int bufferSize)
656 if (!buffer || !bufferSize) return;
657 buffer[0] = (int)VIEW_GRAPHSUPERV;
662 Standard_EXPORT SALOMEGUI* GetComponentGUI() {