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);
77 if (browser) browser->close();
78 MESSAGE("SUPERVGUI Info : factory destroy");
80 MESSAGE("SUPERVGUI Error : another call to factory destructor");
84 void SUPERVGUI::init(QAD_Desktop* parent) {
85 Trace("SUPERVGUI::init")
88 study = desktop->getActiveStudy();
89 SALOME_NamingService* namingService = desktop->getNameService();
90 loadEngine(namingService);
91 browser = new SUPERVGUI_Service(namingService);
92 //info = new SUPERVGUI_Information();
93 cursor = desktop->cursor();
94 connect(desktop->getMainFrame(), SIGNAL(windowActivated(QWidget*)), this, SLOT(setMain(QWidget*)));
97 parent->menuBar()->changeItem(anId,parent->getComponentUserName("SUPERV"));
103 QAD_StudyFrame* SUPERVGUI::createGraph() {
104 QAD_StudyFrame* aStudyFrame = study->newWindow3d(study->getNextStudyFrameName(),
105 VIEW_GRAPHSUPERV, false);
108 SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*)),
110 SLOT(onGraphClosed(QAD_StudyFrame*)));
117 void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) {
118 Trace("SUPERVGUI::loadEngine")
119 SALOME_LifeCycleCORBA LCC(namingService);
120 Engines::Component_var objComponent = LCC.FindOrLoad_Component("SuperVisionContainer", "SUPERV");
121 if (CORBA::is_nil(objComponent)) {
122 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_LOAD_SUPERV"));
126 SUPERV::SuperG_var aSuperVisionComponent;
127 aSuperVisionComponent = SUPERV::SuperG::_narrow(objComponent);
128 if (CORBA::is_nil(aSuperVisionComponent)) {
129 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_NARROW_SUPERV"));
133 // engine = new SUPERV::SuperG_var;
134 engine = aSuperVisionComponent;
137 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
138 Trace("SUPERVGUI::information")
139 return(info->run(node, isReadOnly));
142 void SUPERVGUI::putInfo(const char* mess) {
143 Trace("SUPERVGUI::putInfo")
144 desktop->putInfo(mess);
147 QAD_Desktop* SUPERVGUI::getDesktop() {
148 Trace("SUPERVGUI::getDesktop")
152 SUPERV_Engine SUPERVGUI::getEngine() {
153 Trace("SUPERVGUI::getEngine")
157 SUPERVGUI_Service* SUPERVGUI::getBrowser() {
158 Trace("SUPERVGUI::getBrowser")
162 QCursor SUPERVGUI::getCursor() {
163 Trace("SUPERVGUI::getCursor")
167 SUPERVGUI_Main* SUPERVGUI::getMain() {
168 Trace("SUPERVGUI::getMain")
173 void SUPERVGUI::registerGraph(QString theName, SUPERVGUI_Main* theGraph){
174 theGraph->setHashCode(theName);
175 myGraphList.append(theGraph);
179 void SUPERVGUI::unregisterGraph(SUPERVGUI_Main* theGraph) {
180 SUPERVGUI_Main* aMain;
181 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
182 if (aMain == theGraph)
183 myGraphList.remove(aMain);
188 bool SUPERVGUI::isContains(QAD_Study* theStudy, const QString theKey) {
189 SUPERVGUI_Main* aMain;
190 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
191 if ((aMain->getStudy() == theStudy) && (aMain->getHashCode() == theKey))
198 void SUPERVGUI::onGraphClosed(QAD_StudyFrame* theStudyFrame) {
199 QAD_ViewFrame* viewFrame = theStudyFrame->getRightFrame()->getViewFrame();
200 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
201 disconnect(theStudyFrame, 0 , this, 0);
202 SUPERVGraph_View* view = supervFrame->getViewWidget();
203 SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
205 unregisterGraph(aGraph);
210 void SUPERVGUI::setMain(QWidget* w) {
212 QAD_StudyFrame* aStudyFrame = dynamic_cast<QAD_StudyFrame*>(w);
213 if (!aStudyFrame) return;
215 study = aStudyFrame->getStudy();
218 QAD_ViewFrame* viewFrame = aStudyFrame->getRightFrame()->getViewFrame();
219 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
220 SUPERVGraph_View* view = supervFrame->getViewWidget();
222 main = dynamic_cast<SUPERVGUI_Main*>(view);
224 Trace("SUPERVGUI::setMain - main: "<<main);
228 void SUPERVGUI::importDataflow() {
229 Trace("SUPERVGUI::importDataflow");
230 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
237 if (isContains(study, f)) {
238 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
239 tr("MSG_GRAPH_DISPLAYED").arg(f),
240 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
244 SUPERV_Graph aGraph = engine->StreamGraphE(f);
245 //QFileInfo aFile(f);
246 //aGraph->SetName(aFile.baseName());
247 if (SUPERV_isNull(aGraph)) {
248 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
252 QAD_StudyFrame* aStudyFrame = createGraph();
253 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
254 (aStudyFrame->getRightFrame()->getViewFrame());
256 main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
257 registerGraph(f, main);
258 study->showFrame(aStudyFrame);
263 void SUPERVGUI::displayDataflow() {
264 Trace("SUPERVGUI::displayDataflow");
265 QAD_ObjectBrowser* aBrowser = ((QAD_StudyFrame*)(desktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
266 SUPERV_Graph aDataFlow;
269 QAD_ObjectBrowserItem* item = (QAD_ObjectBrowserItem*)(aBrowser->getListView()->currentItem());
270 SALOMEDS::SObject_var aObj = desktop->getActiveStudy()->getStudyDocument()->FindObjectID(item->getEntry().latin1());
271 SALOMEDS::GenericAttribute_var anAttr;
272 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
273 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
274 Standard_CString ior = anIOR->Value();
276 if (isContains(study, aIORName)) {
277 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
278 tr("MSG_GRAPH_DISPLAYED").arg(""),
279 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
282 aDataFlow = engine->getStreamGraph(ior);
283 if (SUPERV_isNull(aDataFlow)) {
284 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
288 QAD_StudyFrame* aStudyFrame = createGraph();
289 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
290 (aStudyFrame->getRightFrame()->getViewFrame());
292 main = new SUPERVGUI_Main(aViewFrame, desktop, aDataFlow);
293 main->setAsFromStudy(true);
294 registerGraph(aIORName, main);
295 study->showFrame(aStudyFrame);
300 void SUPERVGUI::renameDataflow() {
301 SALOME_Selection* Sel = SALOME_Selection::Selection( study->getSelection() );
302 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
303 for ( ; It.More(); It.Next() ) {
304 Handle(SALOME_InteractiveObject) IObject = It.Value();
306 SALOMEDS::Study_var aStudy = study->getStudyDocument();
307 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
308 SALOMEDS::GenericAttribute_var anAttr;
309 SALOMEDS::AttributeName_var aName;
310 if ( !obj->_is_nil() ) {
311 if (obj->FindAttribute(anAttr, "AttributeName")) {
312 aName = SALOMEDS::AttributeName::_narrow(anAttr);
313 QString nm = QString( aName->Value() );
315 nm = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), nm );
316 if ( !nm.isEmpty() ) {
317 QApplication::setOverrideCursor( Qt::waitCursor );
318 study->renameIObject( IObject, nm );
319 QApplication::restoreOverrideCursor();
327 void SUPERVGUI::exportDataflow() {
328 Trace("SUPERVGUI::exportDataflow")
330 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
332 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
335 tr("TTL_EXPORT_DATAFLOW"),
338 if (main->exportDataflow(f)) {
339 unregisterGraph(main);
340 registerGraph(f, main);
346 void SUPERVGUI::newDataflow() {
347 Trace("SUPERVGUI::editDataflow");
348 QAD_StudyFrame* aStudyFrame = createGraph();
349 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
350 (aStudyFrame->getRightFrame()->getViewFrame());
352 main = new SUPERVGUI_Main(aViewFrame, desktop, false);
354 study->showFrame(aStudyFrame);
358 void SUPERVGUI::modifyDataflow() {
359 Trace("SUPERVGUI::modifyDataflow")
360 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
363 tr("Modify Dataflow"),
366 if (isContains(study, f)) {
367 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
368 tr("MSG_GRAPH_DISPLAYED").arg(f),
369 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
373 SUPERV_Graph aGraph = engine->StreamGraph(f);
375 //aGraph->SetName(aFile.name());
376 if (SUPERV_isNull(aGraph)) {
377 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
381 QAD_StudyFrame* aStudyFrame = createGraph();
382 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
383 (aStudyFrame->getRightFrame()->getViewFrame());
385 main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
386 registerGraph(f, main);
387 study->showFrame(aStudyFrame);
392 void SUPERVGUI::reloadDataflow() {
393 Trace("SUPERVGUI::reloadDataflow")
395 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
401 void SUPERVGUI::runDataflow() {
402 Trace("SUPERVGUI::runDataflow")
404 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
410 void SUPERVGUI::stepByStep() {
411 Trace("SUPERVGUI::stepByStep")
413 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
415 main->startExecute();
419 void SUPERVGUI::killDataflow() {
420 Trace("SUPERVGUI::killDataflow")
422 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
428 void SUPERVGUI::suspendResumeDataflow() {
429 Trace("SUPERVGUI::suspendResumeDataflow")
431 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
433 main->suspendResume();
437 void SUPERVGUI::showComponents() {
438 Trace("SUPERVGUI::showComponents");
440 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
442 if (main->isEditable())
445 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
450 bool SUPERVGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
451 Trace("SUPERVGUI::customPopup");
452 Supervision.init(parent);
453 if(popup->count() > 3) {
454 // Temporary code: is to be deleted soon
455 popup->removeItem(QAD_Display_Popup_ID);
456 popup->removeItem(QAD_DisplayOnly_Popup_ID);
457 popup->removeItem(QAD_Erase_Popup_ID);
458 int id = popup->idAt(popup->count() - 1);
459 if (id < 0 && id != -1) popup->removeItem(id); // separator
460 // Temporary code end
462 SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
463 if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return false;
465 if (Sel->IObjectCount() == 1) {
466 Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject();
468 // insert SUPERV-specific popup items here
470 bool isDataflow, ownObj;
471 whatIsSelected(anIObj, ownObj, isDataflow);
474 popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
475 popup->insertItem("Display", this, SLOT(displayDataflow()));
476 popup->insertSeparator();
479 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
481 if (Sel->IObjectCount() > 1) {
483 SALOME_ListIteratorOfListIO It_forCheckOwner(Sel->StoredIObjects());
484 for(;It_forCheckOwner.More();It_forCheckOwner.Next()) {
485 Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value();
486 bool aIsOwner, aIsDataflow;
487 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
489 if (aIsOwner) aIObjCount++;
491 if (aIObjCount == Sel->IObjectCount()) //all selected objects belong to Supervision
492 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
500 theIsOwner = true if Selected object belongs to Suipervision.
501 theIsDataflow = true if Selected object is Dataflow
503 void SUPERVGUI::whatIsSelected(const Handle(SALOME_InteractiveObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
505 theIsDataflow = false;
507 if (theObj.IsNull()) return;
509 SALOMEDS::Study_var aStudy = study->getStudyDocument();
510 SALOMEDS::SObject_var obj = aStudy->FindObjectID( theObj->getEntry() );
512 if ( !obj->_is_nil() ) {
513 SALOMEDS::SComponent_var comp = obj->GetFatherComponent();
514 if ( !comp->_is_nil() ) {
515 SALOMEDS::GenericAttribute_var anAttr;
516 SALOMEDS::AttributeName_var aName;
517 if (comp->FindAttribute(anAttr, "AttributeName")) {
518 aName = SALOMEDS::AttributeName::_narrow(anAttr);
519 QString compName(aName->Value());
520 //if (compName.compare(STUDY_SUPERVISION) == 0) {
521 if (compName.compare(QAD_Application::getDesktop()->getComponentUserName("SUPERV")) == 0) {
522 SALOMEDS::GenericAttribute_var anAttr;
523 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
524 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
525 SUPERV_Graph aDataFlow = engine->getStreamGraph(anIOR->Value());
526 if (!SUPERV_isNull(aDataFlow))
527 theIsDataflow = true;
529 CORBA::String_var anObjectID = obj->GetID();
530 CORBA::String_var aComponentID = comp->GetID();
531 if (strcmp(anObjectID, aComponentID)) theIsOwner = true;
539 void SUPERVGUI::deleteObject() {
540 SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
541 if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
543 if (QMessageBox::warning(QAD_Application::getDesktop(),
545 tr("MSG_ASK_DELETE"),
547 QMessageBox::Yes) == QMessageBox::No)
550 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
551 for(;It.More();It.Next()) {
552 Handle(SALOME_InteractiveObject) anIObj = It.Value();
553 bool aIsOwner, aIsDataflow;
554 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
556 SALOMEDS::Study_var aStudy = study->getStudyDocument();
557 SALOMEDS::SObject_var aObj = aStudy->FindObjectID( anIObj->getEntry() );
558 if (!aObj->_is_nil()) {
560 SALOMEDS::GenericAttribute_var anAttr;
561 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
562 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
563 QString ior = anIOR->Value();
565 SUPERVGUI_Main* aMain;
566 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
567 if ((aMain->getStudy() == study) && (aMain->getHashCode() == ior)) {
568 aMain->setAsFromStudy(false);
574 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
575 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
577 aBuilder->RemoveObjectWithChildren(aObj);
581 Sel->ClearIObjects() ;
584 bool SUPERVGUI::OnGUIEvent(int command, QAD_Desktop* parent) {
585 Supervision.init(parent);
588 Supervision.importDataflow();
592 Supervision.exportDataflow();
596 Supervision.newDataflow();
600 Supervision.modifyDataflow();
604 Supervision.reloadDataflow();
608 Supervision.runDataflow();
612 Supervision.killDataflow();
616 Supervision.suspendResumeDataflow();
620 Supervision.showComponents();
624 Supervision.stepByStep();
628 QMessageBox::warning(QAD_Application::getDesktop(), "Supervision Error", "Unknown Command From Salome");
633 bool SUPERVGUI::SetSettings(QAD_Desktop* parent) {
634 Trace("SUPERVGUI::SetSettings");
635 Supervision.init(parent);
639 void SUPERVGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject) {
644 bool SUPERVGUI::ActiveStudyChanged(QAD_Desktop* parent) {
645 Trace("SUPERVGUI::activeStudyChanged");
646 study = desktop->getActiveStudy();
650 void SUPERVGUI::SupportedViewType (int* buffer, int bufferSize)
652 if (!buffer || !bufferSize) return;
653 buffer[0] = (int)VIEW_GRAPHSUPERV;
658 Standard_EXPORT SALOMEGUI* GetComponentGUI() {