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(): QObject(),
61 Trace("SUPERVGUI::SUPERVGUI")
64 MESSAGE("SUPERVGUI Info : factory build");
66 MESSAGE("SUPERVGUI Error : another call to factory constructor");
70 SUPERVGUI::~SUPERVGUI() {
71 Trace("SUPERVGUI::~SUPERVGUI")
74 //if (!engine->_is_nil()) CORBA::release(engine);
76 if (browser) browser->close();
77 MESSAGE("SUPERVGUI Info : factory destroy");
79 MESSAGE("SUPERVGUI Error : another call to factory destructor");
83 void SUPERVGUI::init(QAD_Desktop* parent) {
84 Trace("SUPERVGUI::init")
87 study = desktop->getActiveStudy();
88 SALOME_NamingService* namingService = desktop->getNameService();
89 loadEngine(namingService);
90 browser = new SUPERVGUI_Service(namingService);
91 //info = new SUPERVGUI_Information();
92 cursor = desktop->cursor();
93 connect(desktop->getMainFrame(), SIGNAL(windowActivated(QWidget*)), this, SLOT(setMain(QWidget*)));
96 parent->menuBar()->changeItem(anId,parent->getComponentUserName("SUPERV"));
102 QAD_StudyFrame* SUPERVGUI::createGraph() {
103 QAD_StudyFrame* aStudyFrame = study->newWindow3d(study->getNextStudyFrameName(),
104 VIEW_GRAPHSUPERV, false);
107 SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*)),
109 SLOT(onGraphClosed(QAD_StudyFrame*)));
116 void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) {
117 Trace("SUPERVGUI::loadEngine")
118 SALOME_LifeCycleCORBA LCC(namingService);
119 Engines::Component_var objComponent = LCC.FindOrLoad_Component("SuperVisionContainer", "SUPERV");
120 if (CORBA::is_nil(objComponent)) {
121 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_LOAD_SUPERV"));
125 SUPERV::SuperG_var aSuperVisionComponent;
126 aSuperVisionComponent = SUPERV::SuperG::_narrow(objComponent);
127 if (CORBA::is_nil(aSuperVisionComponent)) {
128 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_NARROW_SUPERV"));
132 // engine = new SUPERV::SuperG_var;
133 engine = aSuperVisionComponent;
136 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
137 Trace("SUPERVGUI::information")
138 return(info->run(node, isReadOnly));
141 void SUPERVGUI::putInfo(const char* mess) {
142 Trace("SUPERVGUI::putInfo")
143 desktop->putInfo(mess);
146 QAD_Desktop* SUPERVGUI::getDesktop() {
147 Trace("SUPERVGUI::getDesktop")
151 SUPERV_Engine SUPERVGUI::getEngine() {
152 Trace("SUPERVGUI::getEngine")
156 SUPERVGUI_Service* SUPERVGUI::getBrowser() {
157 Trace("SUPERVGUI::getBrowser")
161 QCursor SUPERVGUI::getCursor() {
162 Trace("SUPERVGUI::getCursor")
166 SUPERVGUI_Main* SUPERVGUI::getMain() {
167 Trace("SUPERVGUI::getMain")
172 void SUPERVGUI::registerGraph(QString theName, SUPERVGUI_Main* theGraph){
173 theGraph->setHashCode(theName);
174 myGraphList.append(theGraph);
178 void SUPERVGUI::unregisterGraph(SUPERVGUI_Main* theGraph) {
179 SUPERVGUI_Main* aMain;
180 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
181 if (aMain == theGraph)
182 myGraphList.remove(aMain);
187 bool SUPERVGUI::isContains(QAD_Study* theStudy, const QString theKey) {
188 SUPERVGUI_Main* aMain;
189 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
190 if ((aMain->getStudy() == theStudy) && (aMain->getHashCode() == theKey))
197 void SUPERVGUI::onGraphClosed(QAD_StudyFrame* theStudyFrame) {
198 QAD_ViewFrame* viewFrame = theStudyFrame->getRightFrame()->getViewFrame();
199 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
200 disconnect(theStudyFrame, 0 , this, 0);
201 SUPERVGraph_View* view = supervFrame->getViewWidget();
202 SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
204 unregisterGraph(aGraph);
209 void SUPERVGUI::setMain(QWidget* w) {
211 QAD_StudyFrame* aStudyFrame = dynamic_cast<QAD_StudyFrame*>(w);
212 if (!aStudyFrame) return;
214 study = aStudyFrame->getStudy();
217 QAD_ViewFrame* viewFrame = aStudyFrame->getRightFrame()->getViewFrame();
218 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
219 SUPERVGraph_View* view = supervFrame->getViewWidget();
221 main = dynamic_cast<SUPERVGUI_Main*>(view);
223 Trace("SUPERVGUI::setMain - main: "<<main);
227 void SUPERVGUI::importDataflow() {
228 Trace("SUPERVGUI::importDataflow");
229 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
236 if (isContains(study, f)) {
237 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
238 tr("MSG_GRAPH_DISPLAYED").arg(f),
239 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
243 SUPERV_Graph aGraph = engine->GraphE(f);
244 //QFileInfo aFile(f);
245 //aGraph->SetName(aFile.baseName());
246 if (SUPERV_isNull(aGraph)) {
247 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
251 QAD_StudyFrame* aStudyFrame = createGraph();
252 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
253 (aStudyFrame->getRightFrame()->getViewFrame());
255 main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
256 registerGraph(f, main);
257 study->showFrame(aStudyFrame);
262 void SUPERVGUI::displayDataflow() {
263 Trace("SUPERVGUI::displayDataflow");
264 QAD_ObjectBrowser* aBrowser = ((QAD_StudyFrame*)(desktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
265 SUPERV_Graph aDataFlow;
268 QAD_ObjectBrowserItem* item = (QAD_ObjectBrowserItem*)(aBrowser->getListView()->currentItem());
269 SALOMEDS::SObject_var aObj = desktop->getActiveStudy()->getStudyDocument()->FindObjectID(item->getEntry().latin1());
270 SALOMEDS::GenericAttribute_var anAttr;
271 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
272 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
273 Standard_CString ior = anIOR->Value();
275 if (isContains(study, aIORName)) {
276 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
277 tr("MSG_GRAPH_DISPLAYED").arg(""),
278 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
281 aDataFlow = engine->getGraph(ior);
282 if (SUPERV_isNull(aDataFlow)) {
283 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
287 QAD_StudyFrame* aStudyFrame = createGraph();
288 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
289 (aStudyFrame->getRightFrame()->getViewFrame());
291 main = new SUPERVGUI_Main(aViewFrame, desktop, aDataFlow);
292 main->setAsFromStudy(true);
293 registerGraph(aIORName, main);
294 study->showFrame(aStudyFrame);
299 void SUPERVGUI::renameDataflow() {
300 SALOME_Selection* Sel = SALOME_Selection::Selection( study->getSelection() );
301 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
302 for ( ; It.More(); It.Next() ) {
303 Handle(SALOME_InteractiveObject) IObject = It.Value();
305 SALOMEDS::Study_var aStudy = study->getStudyDocument();
306 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
307 SALOMEDS::GenericAttribute_var anAttr;
308 SALOMEDS::AttributeName_var aName;
309 if ( !obj->_is_nil() ) {
310 if (obj->FindAttribute(anAttr, "AttributeName")) {
311 aName = SALOMEDS::AttributeName::_narrow(anAttr);
312 QString nm = QString( aName->Value() );
314 nm = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), nm );
315 if ( !nm.isEmpty() ) {
316 QApplication::setOverrideCursor( Qt::waitCursor );
317 study->renameIObject( IObject, nm );
318 QApplication::restoreOverrideCursor();
326 void SUPERVGUI::exportDataflow() {
327 Trace("SUPERVGUI::exportDataflow")
329 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
331 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
334 tr("TTL_EXPORT_DATAFLOW"),
337 if (main->exportDataflow(f)) {
338 unregisterGraph(main);
339 registerGraph(f, main);
345 void SUPERVGUI::newDataflow() {
346 Trace("SUPERVGUI::editDataflow");
347 QAD_StudyFrame* aStudyFrame = createGraph();
348 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
349 (aStudyFrame->getRightFrame()->getViewFrame());
351 main = new SUPERVGUI_Main(aViewFrame, desktop, false);
353 study->showFrame(aStudyFrame);
357 void SUPERVGUI::modifyDataflow() {
358 Trace("SUPERVGUI::modifyDataflow")
359 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
362 tr("Modify Dataflow"),
365 if (isContains(study, f)) {
366 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
367 tr("MSG_GRAPH_DISPLAYED").arg(f),
368 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
372 SUPERV_Graph aGraph = engine->Graph(f);
374 //aGraph->SetName(aFile.name());
375 if (SUPERV_isNull(aGraph)) {
376 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
380 QAD_StudyFrame* aStudyFrame = createGraph();
381 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
382 (aStudyFrame->getRightFrame()->getViewFrame());
384 main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
385 registerGraph(f, main);
386 study->showFrame(aStudyFrame);
391 void SUPERVGUI::reloadDataflow() {
392 Trace("SUPERVGUI::reloadDataflow")
394 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
400 void SUPERVGUI::runDataflow() {
401 Trace("SUPERVGUI::runDataflow")
403 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
409 void SUPERVGUI::stepByStep() {
410 Trace("SUPERVGUI::stepByStep")
412 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
414 main->startExecute();
418 void SUPERVGUI::killDataflow() {
419 Trace("SUPERVGUI::killDataflow")
421 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
427 void SUPERVGUI::suspendResumeDataflow() {
428 Trace("SUPERVGUI::suspendResumeDataflow")
430 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
432 main->suspendResume();
436 void SUPERVGUI::showComponents() {
437 Trace("SUPERVGUI::showComponents");
439 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
441 if (main->isEditable())
444 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
448 void SUPERVGUI::customPopup(QPopupMenu* popup) {
449 Trace("SUPERVGUI::customPopup");
450 if(popup->count() > 3) {
451 // Temporary code: is to be deleted soon
452 popup->removeItem(QAD_Display_Popup_ID);
453 popup->removeItem(QAD_DisplayOnly_Popup_ID);
454 popup->removeItem(QAD_Erase_Popup_ID);
455 int id = popup->idAt(popup->count() - 1);
456 if (id < 0 && id != -1) popup->removeItem(id); // separator
457 // Temporary code end
459 SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
460 if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
462 if (Sel->IObjectCount() == 1) {
463 Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject();
465 // insert SUPERV-specific popup items here
467 bool isDataflow, ownObj;
468 whatIsSelected(anIObj, ownObj, isDataflow);
471 popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
472 popup->insertItem("Display", this, SLOT(displayDataflow()));
473 popup->insertSeparator();
476 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
478 if (Sel->IObjectCount() > 1) {
480 SALOME_ListIteratorOfListIO It_forCheckOwner(Sel->StoredIObjects());
481 for(;It_forCheckOwner.More();It_forCheckOwner.Next()) {
482 Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value();
483 bool aIsOwner, aIsDataflow;
484 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
486 if (aIsOwner) aIObjCount++;
488 if (aIObjCount == Sel->IObjectCount()) //all selected objects belong to Supervision
489 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
496 theIsOwner = true if Selected object belongs to Suipervision.
497 theIsDataflow = true if Selected object is Dataflow
499 void SUPERVGUI::whatIsSelected(const Handle(SALOME_InteractiveObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
501 theIsDataflow = false;
503 if (theObj.IsNull()) return;
505 SALOMEDS::Study_var aStudy = study->getStudyDocument();
506 SALOMEDS::SObject_var obj = aStudy->FindObjectID( theObj->getEntry() );
508 if ( !obj->_is_nil() ) {
509 SALOMEDS::SComponent_var comp = obj->GetFatherComponent();
510 if ( !comp->_is_nil() ) {
511 SALOMEDS::GenericAttribute_var anAttr;
512 SALOMEDS::AttributeName_var aName;
513 if (comp->FindAttribute(anAttr, "AttributeName")) {
514 aName = SALOMEDS::AttributeName::_narrow(anAttr);
515 QString compName(aName->Value());
516 //if (compName.compare(STUDY_SUPERVISION) == 0) {
517 if (compName.compare(QAD_Application::getDesktop()->getComponentUserName("SUPERV")) == 0) {
518 SALOMEDS::GenericAttribute_var anAttr;
519 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
520 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
521 SUPERV_Graph aDataFlow = engine->getGraph(anIOR->Value());
522 if (!SUPERV_isNull(aDataFlow))
523 theIsDataflow = true;
525 CORBA::String_var anObjectID = obj->GetID();
526 CORBA::String_var aComponentID = comp->GetID();
527 if (strcmp(anObjectID, aComponentID)) theIsOwner = true;
535 void SUPERVGUI::deleteObject() {
536 SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
537 if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
539 if (QMessageBox::warning(QAD_Application::getDesktop(),
541 tr("MSG_ASK_DELETE"),
543 QMessageBox::Yes) == QMessageBox::No)
546 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
547 for(;It.More();It.Next()) {
548 Handle(SALOME_InteractiveObject) anIObj = It.Value();
549 bool aIsOwner, aIsDataflow;
550 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
552 SALOMEDS::Study_var aStudy = study->getStudyDocument();
553 SALOMEDS::SObject_var aObj = aStudy->FindObjectID( anIObj->getEntry() );
554 if (!aObj->_is_nil()) {
556 SALOMEDS::GenericAttribute_var anAttr;
557 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
558 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
559 QString ior = anIOR->Value();
561 SUPERVGUI_Main* aMain;
562 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
563 if ((aMain->getStudy() == study) && (aMain->getHashCode() == ior)) {
564 aMain->setAsFromStudy(false);
570 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
571 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
573 aBuilder->RemoveObjectWithChildren(aObj);
577 Sel->ClearIObjects() ;
582 void SUPERVGUI::activeStudyChanged() {
583 Trace("SUPERVGUI::activeStudyChanged");
584 study = desktop->getActiveStudy();
587 extern "C" bool OnGUIEvent(int command, QAD_Desktop* parent) {
588 Supervision.init(parent);
591 Supervision.importDataflow();
595 Supervision.exportDataflow();
599 Supervision.newDataflow();
603 Supervision.modifyDataflow();
607 Supervision.reloadDataflow();
611 Supervision.runDataflow();
615 Supervision.killDataflow();
619 Supervision.suspendResumeDataflow();
623 Supervision.showComponents();
627 Supervision.stepByStep();
631 QMessageBox::warning(QAD_Application::getDesktop(), "Supervision Error", "Unknown Command From Salome");
637 extern "C" bool OnKeyPress(QKeyEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
641 extern "C" bool OnMousePress(QMouseEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
645 extern "C" bool OnMouseMove(QMouseEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
649 extern "C" bool OnPopupGUIEvent(int theCommandID, QAD_Desktop* parent) {
653 extern "C" bool SetSettings(QAD_Desktop* parent) {
654 Trace("extern SUPERVGUI::SetSettings")
655 Supervision.init(parent);
659 extern "C" void definePopup(QString& theContext, QString& theParent, QString& theObject) {
664 extern "C" bool customPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
665 Supervision.init(parent);
666 Supervision.customPopup(popup);
670 extern "C" void activeStudyChanged(QAD_Desktop* parent) {
671 Supervision.activeStudyChanged();
674 extern "C" int supportedViewType()
676 return (int)VIEW_GRAPHSUPERV;
679 extern "C" void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )