From f57828e2d4e246d20ef8df6b216aaa476667f3bc Mon Sep 17 00:00:00 2001 From: asv Date: Mon, 7 Feb 2005 05:49:55 +0000 Subject: [PATCH] Fixes for bugs PAL7846, PAL7987. "Add dataflow in Study", "Put out-port value to study" functionalities are re-viewed and improved. --- src/SUPERVGUI/SUPERVGUI.cxx | 16 -- src/SUPERVGUI/SUPERVGUI_ArrayView.cxx | 9 +- src/SUPERVGUI/SUPERVGUI_Canvas.cxx | 17 -- src/SUPERVGUI/SUPERVGUI_CanvasPort.cxx | 9 +- src/SUPERVGUI/SUPERVGUI_CanvasView.cxx | 10 +- src/SUPERVGUI/SUPERVGUI_Main.cxx | 208 +++++++++++-------------- src/SUPERVGUI/SUPERVGUI_Main.h | 14 +- 7 files changed, 101 insertions(+), 182 deletions(-) diff --git a/src/SUPERVGUI/SUPERVGUI.cxx b/src/SUPERVGUI/SUPERVGUI.cxx index 8b29eec..d8055e4 100644 --- a/src/SUPERVGUI/SUPERVGUI.cxx +++ b/src/SUPERVGUI/SUPERVGUI.cxx @@ -308,7 +308,6 @@ void SUPERVGUI::displayDataflow() { (aStudyFrame->getRightFrame()->getViewFrame()); if(aViewFrame) { main = new SUPERVGUI_Main(aViewFrame, desktop, aDataFlow); - main->setAsFromStudy(true); registerGraph(aIORName, main); study->showFrame(aStudyFrame); } @@ -653,21 +652,6 @@ void SUPERVGUI::deleteObject() { SALOMEDS::SObject_var aObj = aStudy->FindObjectID( anIObj->getEntry() ); if (!aObj->_is_nil()) { - if (aIsDataflow) { - SALOMEDS::GenericAttribute_var anAttr; - if (aObj->FindAttribute(anAttr, "AttributeIOR")) { - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - QString ior = anIOR->Value(); - - SUPERVGUI_Main* aMain; - for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) { - if ((aMain->getStudy() == study) && (aMain->getHashCode() == ior)) { - aMain->setAsFromStudy(false); - break; - } - } - } - } QAD_Operation* op = new SALOMEGUI_ImportOperation( study ); SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder(); op->start(); diff --git a/src/SUPERVGUI/SUPERVGUI_ArrayView.cxx b/src/SUPERVGUI/SUPERVGUI_ArrayView.cxx index 16561b0..b2b0309 100644 --- a/src/SUPERVGUI/SUPERVGUI_ArrayView.cxx +++ b/src/SUPERVGUI/SUPERVGUI_ArrayView.cxx @@ -60,7 +60,7 @@ SUPERVGUI_ArrayView::SUPERVGUI_ArrayView(SUPERVGUI_CanvasArray* theArray, SUPERV myPopup->insertItem("Zoom", aZoomPopup); myPopup->insertSeparator();*/ - myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), this, SLOT(addToStudy())); + myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), myMain, SLOT(addDataflowToStudy())); myPopup->insertItem(tr("MSG_CHANGE_INFO"), myMain, SLOT(changeInformation())); myPopup->insertSeparator(); @@ -91,11 +91,6 @@ void SUPERVGUI_ArrayView::ResetView() setWorldMatrix(m); } -void SUPERVGUI_ArrayView::addToStudy() -{ - if (myMain->addStudy()) myMain->setAsFromStudy(true); -} - void SUPERVGUI_ArrayView::changeBackground() { QColor aColor = QColorDialog::getColor(canvas()->backgroundColor(), this ); @@ -137,7 +132,7 @@ void SUPERVGUI_ArrayView::contentsMousePressEvent(QMouseEvent* theEvent) { } } - myPopup->setItemEnabled(myAddStudyItem, !myMain->isFromStudy()); + myPopup->setItemEnabled(myAddStudyItem, !myMain->isDataflowInStudy()); myMain->showPopup(myPopup, theEvent); return; } diff --git a/src/SUPERVGUI/SUPERVGUI_Canvas.cxx b/src/SUPERVGUI/SUPERVGUI_Canvas.cxx index 566a761..58d6e2a 100644 --- a/src/SUPERVGUI/SUPERVGUI_Canvas.cxx +++ b/src/SUPERVGUI/SUPERVGUI_Canvas.cxx @@ -275,23 +275,6 @@ void SUPERVGUI_Canvas::merge() { delete ihmList; } -void SUPERVGUI_Canvas::setAsFromStudy(bool theToStudy) -{ - if (theToStudy) return; - - SUPERVGUI_CanvasPortOut* aPortOut; - QObjectList* aPortList = queryList("SUPERVGUI_CanvasPortOut"); - QObjectListIt aPortIt(*aPortList); - while ((aPortOut=(SUPERVGUI_CanvasPortOut*)aPortIt.current()) != 0) { - ++aPortIt; - if (aPortOut->isInStudy()) { - aPortOut->setStudyState(theToStudy); - aPortOut->sync(); - } - } - delete aPortList; -} - SUPERVGUI_CanvasNode* SUPERVGUI_Canvas::getNode(SUPERV::CNode_ptr theNode) const { return (SUPERVGUI_CanvasNode*) diff --git a/src/SUPERVGUI/SUPERVGUI_CanvasPort.cxx b/src/SUPERVGUI/SUPERVGUI_CanvasPort.cxx index 859611e..8ff068b 100644 --- a/src/SUPERVGUI/SUPERVGUI_CanvasPort.cxx +++ b/src/SUPERVGUI/SUPERVGUI_CanvasPort.cxx @@ -297,15 +297,12 @@ void SUPERVGUI_CanvasPortOut::toStudy() return; } - if ( !getMain()->isFromStudy() ) { - if ( getMain()->addStudy() ) { - getMain()->setAsFromStudy( true ); // put an "computation" item under "Supervisor" item in the Study tree - getMain()->putDataStudy( getEngine(), STUDY_PORT_OUT ); // put another new item under some another corresponding item - } // GEOM -> Compound_1 - } myInStudy = !myInStudy; sync(); getMain()->getCanvas()->update(); + + if ( myInStudy ) // put values to study (supervision, supervision->dataflow, supervision->dataflow->runXXX, etc. + getMain()->putDataStudy( getEngine(), STUDY_PORT_OUT ); } diff --git a/src/SUPERVGUI/SUPERVGUI_CanvasView.cxx b/src/SUPERVGUI/SUPERVGUI_CanvasView.cxx index e4587d9..ad96187 100644 --- a/src/SUPERVGUI/SUPERVGUI_CanvasView.cxx +++ b/src/SUPERVGUI/SUPERVGUI_CanvasView.cxx @@ -131,7 +131,7 @@ SUPERVGUI_CanvasView::SUPERVGUI_CanvasView(SUPERVGUI_Canvas* theCanvas, SUPERVGU myPopup->insertItem(tr("POP_ZOOM"), aZoomPopup); myPopup->insertSeparator(); - myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), this, SLOT(addToStudy())); + myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), myMain, SLOT(addDataflowToStudy())); myPopup->insertItem(tr(isEdit ? "MSG_CHANGE_INFO" : "MSG_INFO"), myMain, SLOT(changeInformation())); myPopup->insertSeparator(); @@ -221,7 +221,7 @@ void SUPERVGUI_CanvasView::contentsMousePressEvent(QMouseEvent* theEvent) } } - myPopup->setItemEnabled(myAddStudyItem, !myMain->isFromStudy()); + myPopup->setItemEnabled(myAddStudyItem, !myMain->isDataflowInStudy()); // Paste Node functionality SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard(); myPopup->setItemEnabled(myPasteNodeItem, aCB->isCopyNode() ); @@ -686,12 +686,6 @@ void SUPERVGUI_CanvasView::setOrthoMode() mySketchPopup->setItemChecked(myOrtoItem, aIsOrtho); } - -void SUPERVGUI_CanvasView::addToStudy() -{ - if (myMain->addStudy()) myMain->setAsFromStudy(true); -} - void SUPERVGUI_CanvasView::zoomIn() { QWMatrix m; diff --git a/src/SUPERVGUI/SUPERVGUI_Main.cxx b/src/SUPERVGUI/SUPERVGUI_Main.cxx index 4ef006a..6facd78 100644 --- a/src/SUPERVGUI/SUPERVGUI_Main.cxx +++ b/src/SUPERVGUI/SUPERVGUI_Main.cxx @@ -68,8 +68,8 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th myWarning( false ), myStep( false ), myTrace( false ), - myVerbose( false ), - myExecuted( false ) + myVerbose( false ) + //myExecuted( false ) { Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)"); theParent->setViewWidget(this); @@ -222,8 +222,8 @@ void SUPERVGUI_Main::filterNotification() { } void SUPERVGUI_Main::syncAsync() { - Trace("SUPERVGUI_Main::syncAsync"); - QTimer::singleShot(1, this, SLOT(sync())); + Trace("SUPERVGUI_Main::syncAsync"); + QTimer::singleShot(1, this, SLOT(sync())); } @@ -518,7 +518,7 @@ void SUPERVGUI_Main::run( const bool andSuspend ) { } } else { - myExecuted = true; // set to true on first execution. for correct publishing in Study + //myExecuted = true; // set to true on first execution. for correct publishing in Study myThread->startThread(tr("MSG_GRAPH_STARTED")); } } @@ -756,14 +756,11 @@ void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) { //if (QAD_Application::getDesktop()->getActiveComponent().compare(STUDY_SUPERVISION) !=0) return; if (QAD_Application::getDesktop()->getActiveComponent().compare(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ) !=0) return; - checkIsInStudy(); if (e->button() == RightButton) { p->exec(e->globalPos()); } } - - void SUPERVGUI_Main::changeInformation() { SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly()); if (aDlg->exec() ) @@ -771,66 +768,6 @@ void SUPERVGUI_Main::changeInformation() { delete aDlg; } -// returns false, if can't add dataflow into the study -bool SUPERVGUI_Main::addStudy() { - Trace("SUPERVGUI_Main::addStudy"); - if (myIsFromStudy) return false; - if ((SUPERV_isNull(dataflow))) return false; - - SALOMEDS::Study_var aStudy = study->getStudyDocument(); - bool aLocked = aStudy->GetProperties()->IsLocked(); - // asv : 23.11.04 : if the study is locked -- then we can't put anything in it. - // fix for PAL6852. - if ( aLocked ) - return false; - - SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder(); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIORAttr; - SALOMEDS::AttributePixMap_var aPixmap; - QAD_Operation* op = new SALOMEGUI_ImportOperation( study ); - - // searching dataflow - SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR()); - if (aSO->_is_nil()) { // create new dataflow SObject - SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION); - if (aComponent->_is_nil()) { // is supervision component not found, then create it - QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study ); - anOperation->start(); - //if (aLocked) aStudy->GetProperties()->SetLocked(false); - aComponent = aBuilder->NewComponent(STUDY_SUPERVISION); - anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - //aName->SetValue(STUDY_SUPERVISION); - aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ); - anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap"); - aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); - aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" ); - aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine()); - //if (aLocked) aStudy->GetProperties()->SetLocked(true); - anOperation->finish(); - } - op->start(); - aSO = aBuilder->NewObject(aComponent); - anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue(dataflow->Name()); - anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR"); - anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr); - anIORAttr->SetValue(dataflow->getIOR()); - op->finish(); - //if (aLocked) return false; - } - - sync(); - Supervision.unregisterGraph(this); - Supervision.registerGraph(dataflow->getIOR(), this); - myIsFromStudy = true; - return true; -} - - void SUPERVGUI_Main::chooseData(QListViewItem* item) { Trace("SUPERVGUI_Main::chooseData"); if (choosing) { @@ -890,34 +827,30 @@ SALOMEDS::SObject_var SearchOrCreateSOWithName(const SALOMEDS::Study_var theStud aName->SetValue(theName); return aResult; } + +/** + * Return true if dataflow is already in the study + */ +bool SUPERVGUI_Main::isDataflowInStudy() const { + SALOMEDS::Study_var aStudy = study->getStudyDocument(); + SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR( dataflow->getIOR() ); + return ( !CORBA::is_nil( aSO ) ); +} -bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) { - Trace("SUPERVGUI_Main::putDataStudy"); - - // static variable to ensure that only one instance (thread) is executing this function - static bool isIn = false; - if (isIn) return true; - else isIn = true; - +/** + * Create a "Supervision" object in the Study and a "dataflow" object under it + * aDoneSomething will be true if "Supervision" or "dataflow" object were created (not found). + */ +SALOMEDS::SObject_var createDataflowSObj( QAD_Study* study, + SUPERV::Graph_var dataflow, + SALOMEDS::StudyBuilder_var aBuilder, + bool& aDoneSomething ) { SALOMEDS::Study_var aStudy = study->getStudyDocument(); - const bool aLocked = aStudy->GetProperties()->IsLocked(); - SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeName_var aName; SALOMEDS::AttributeIOR_var anIORAttr; SALOMEDS::AttributePixMap_var aPixmap; - bool aDoneSomething = false; - - // asv 23.11.04 : fix for PAL6852 if the study is locked -- then we can't put anything in it. - if ( aLocked ) { - MESSAGE( "The study is locked and can not be modified!" ); - isIn = false; - return false; - } - // open new command. Commit or Abort it depending on aDoneSomething variable or error - aBuilder->NewCommand(); - // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR( dataflow->getIOR() ); if ( aSO->_is_nil() ) { // dataflow SObject not found in the study @@ -944,8 +877,75 @@ bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) { anIORAttr->SetValue(dataflow->getIOR()); } + return aSO; +} + +void SUPERVGUI_Main::addDataflowToStudy() { + bool isCreated; + SALOMEDS::StudyBuilder_var aBuilder = study->getStudyDocument()->NewBuilder(); + aBuilder->NewCommand(); + SALOMEDS::SObject_var aDF = createDataflowSObj( study, dataflow, aBuilder, isCreated ); + if ( !CORBA::is_nil( aDF ) ) { + aBuilder->CommitCommand(); + // what is this register/unregister?? don't know.. + Supervision.unregisterGraph(this); + Supervision.registerGraph(dataflow->getIOR(), this); + + if ( !myThread->running() ) + study->updateObjBrowser(); + } + else { + MESSAGE( "ERROR: failed to find or create dataflow SObject" ); + aBuilder->AbortCommand(); + } +} + +bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) { + Trace("SUPERVGUI_Main::putDataStudy"); + + // static variable to ensure that only one instance (thread) is executing this function + static bool isIn = false; + if (isIn) return true; + else isIn = true; + + SALOMEDS::Study_var aStudy = study->getStudyDocument(); + const bool aLocked = aStudy->GetProperties()->IsLocked(); + SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder(); + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::AttributeIOR_var anIORAttr; + SALOMEDS::AttributePixMap_var aPixmap; + bool aDoneSomething = false; + + // asv 23.11.04 : fix for PAL6852 if the study is locked -- then we can't put anything in it. + if ( aLocked ) { + MESSAGE( "The study is locked and can not be modified!" ); + isIn = false; + return false; + } + + // check if the port and its node are good + if ( CORBA::is_nil( p ) || CORBA::is_nil( p->Node() ) ) { + MESSAGE( "putInStudy ERROR: port or node are NULL!" ); + isIn = false; + return false; + } + + // open new command. Commit or Abort it depending on aDoneSomething variable or error + aBuilder->NewCommand(); + + // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study + SALOMEDS::SObject_var aSO = createDataflowSObj( study, dataflow, aBuilder, aDoneSomething ); + + if ( CORBA::is_nil( aSO ) ) { + MESSAGE( "ERROR: putDataStudy() could not find or create dataflow SObject" ); + aBuilder->AbortCommand(); + isIn = false; + return false; + } + // Create "Run -> Time and date, etc." SObjects - if ( myExecuted ) { // if dataflow was executed at least once + if ( p->State() == SUPERV::ReadyState ) { // if port contains valid computed value + aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, QString("Run ") + myRunTime.toString(), &aDoneSomething ); // get run time SO aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Node()->Name(), &aDoneSomething ); // get node SO aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, inout, &aDoneSomething ); // get in/out SO @@ -1047,34 +1047,6 @@ void SUPERVGUI_Main::ResetView() } } - -void SUPERVGUI_Main::setAsFromStudy(bool theToStudy) { - myIsFromStudy = theToStudy; - myCanvas->setAsFromStudy(theToStudy); -} - -void SUPERVGUI_Main::checkIsInStudy() { - if (!myIsFromStudy) return; - - SALOMEDS::Study_var aStudyDoc = study->getStudyDocument(); - SALOMEDS::SComponent_var aFatherLbl = aStudyDoc->FindComponent(STUDY_SUPERVISION); - SALOMEDS::ChildIterator_var aChildIterator = aStudyDoc->NewChildIterator(aFatherLbl); - SALOMEDS::SObject_var aDataflowLbl; - SALOMEDS::GenericAttribute_var anAttr; - - for (; aChildIterator->More(); aChildIterator->Next()) { - aDataflowLbl = aChildIterator->Value(); - if (!aDataflowLbl->FindAttribute(anAttr, "AttributeIOR")) - continue; - - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - if (strcmp(anIOR->Value(), dataflow->getIOR()) == 0) return; - } - // This Graph considered as in study but in study it is not exists - Supervision.unregisterGraph(this); - setAsFromStudy(false); -} - void SUPERVGUI_Main::syncNotification() { char* graph; char* node; diff --git a/src/SUPERVGUI/SUPERVGUI_Main.h b/src/SUPERVGUI/SUPERVGUI_Main.h index ef8bd80..9321579 100644 --- a/src/SUPERVGUI/SUPERVGUI_Main.h +++ b/src/SUPERVGUI/SUPERVGUI_Main.h @@ -84,16 +84,13 @@ class SUPERVGUI_Main: public SUPERVGraph_View { QString getHashCode() { return myHashCode; }; - + + bool isDataflowInStudy() const; bool isEditable() { if (SUPERV_isNull(dataflow)) return false; return !dataflow->IsReadOnly(); }; - bool isFromStudy() { return myIsFromStudy; } - void setAsFromStudy(bool theToStudy); - void checkIsInStudy(); - void addComputeNode(SUPERV_CNode theNode); void addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update); void addGOTONode(SUPERV_CNode theNode); @@ -139,7 +136,7 @@ class SUPERVGUI_Main: public SUPERVGraph_View { void execute(char * theNodeNode, SUPERV::GraphState theNodeState); void sync(); void syncAsync(); - bool addStudy(); + void addDataflowToStudy(); void insertFile(); void addNode(); void changeInformation(); @@ -174,7 +171,7 @@ class SUPERVGUI_Main: public SUPERVGraph_View { QAD_ObjectBrowser* objectBrowser; QAD_Message* message; - GraphViewType myCurrentView; + GraphViewType myCurrentView; SUPERVGUI_CanvasArray* myArray; SUPERVGUI_ArrayView* myArrayView; SUPERVGUI_Canvas* myCanvas; @@ -207,9 +204,6 @@ class SUPERVGUI_Main: public SUPERVGraph_View { QPtrList< char * > myEventNodes ; QPtrList< SUPERV::GraphState > myStates ; QTimer* myTimer; - - bool myExecuted; // asv 02.02.05 : set to true on first dataflow execution - // is needed for correct publishing objects in Study }; class SUPERVGUI_Thread : public QObject, public QThread { -- 2.39.2