From: asv Date: Mon, 10 Jan 2005 06:13:52 +0000 (+0000) Subject: Copy/Paste ports and nodes functionality was transfered to SUPERVGUI_Clipboard class... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b988face99ea0bc5ba62cd454154645246791126;p=modules%2Fsuperv.git Copy/Paste ports and nodes functionality was transfered to SUPERVGUI_Clipboard class. All references to the functions in various classes were modified to reflect this change. --- diff --git a/src/SUPERVGUI/Makefile.in b/src/SUPERVGUI/Makefile.in index 6378722..f9d6866 100644 --- a/src/SUPERVGUI/Makefile.in +++ b/src/SUPERVGUI/Makefile.in @@ -65,7 +65,8 @@ LIB_SRC = SUPERVGUI.cxx \ SUPERVGUI_Information.cxx \ SUPERVGUI_Notification.cxx \ SUPERVGUI_ManagePortsDlg.cxx \ - SUPERVGUI_Library.cxx + SUPERVGUI_Library.cxx \ + SUPERVGUI_Clipboard.cxx LIB_MOC = SUPERVGUI.h \ SUPERVGUI_ArrayView.h \ @@ -82,7 +83,8 @@ LIB_MOC = SUPERVGUI.h \ SUPERVGUI_Information.h \ SUPERVGUI_Notification.h \ SUPERVGUI_ManagePortsDlg.h \ - SUPERVGUI_Library.h + SUPERVGUI_Library.h \ + SUPERVGUI_Clipboard.h LIB_CLIENT_IDL = SALOMEDS.idl \ SALOMEDS_Attributes.idl \ diff --git a/src/SUPERVGUI/SUPERVGUI_CanvasControlNode.cxx b/src/SUPERVGUI/SUPERVGUI_CanvasControlNode.cxx index 7fe0df8..4f850b0 100644 --- a/src/SUPERVGUI/SUPERVGUI_CanvasControlNode.cxx +++ b/src/SUPERVGUI/SUPERVGUI_CanvasControlNode.cxx @@ -10,6 +10,7 @@ using namespace std; #include "SUPERVGUI_CanvasControlNode.h" #include "SUPERVGUI_CanvasControlNodePrs.h" #include "SUPERVGUI_CanvasCellNodePrs.h" +#include "SUPERVGUI_Clipboard.h" #include "SUPERVGUI_Main.h" #include "SUPERVGUI.h" #include "SUPERVGUI_Canvas.h" @@ -87,28 +88,30 @@ void SUPERVGUI_CanvasStartNode::remove() SUPERVGUI_Canvas* aCanvas = getMain()->getCanvas(); setDestroyed(); + SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard(); if (myCoupled) { //set myCopyPort from Main object to empty if engine of this port is deleted //check if any port of this deleted node has been copied - if (!SUPERV_isNull(getMain()->getCopyPort()) || getMain()->getCopyPort()) - if ((QString(getEngine()->Name())).compare(QString(getMain()->getCopyPort()->Node()->Name())) == 0 - || - (QString(myCoupled->getEngine()->Name())).compare(QString(getMain()->getCopyPort()->Node()->Name())) == 0) - getMain()->setCopyPort(NULL); + if ( aCB->isCopyPort() ) + if ( QString(getEngine()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) || + QString(myCoupled->getEngine()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) ) + aCB->setCopyPort( 0 ); myCoupled->setDestroyed(); } //set myCopyNode from Main object to empty if engine of this node is deleted //check if myCopyNode and this node engine is equal - if (!SUPERV_isNull(getMain()->getCopyNode()) || getMain()->getCopyNode()) - if ((QString(getEngine()->Name())).compare(QString(getMain()->getCopyNode()->Name())) == 0) - getMain()->setCopyNode(NULL); + if ( aCB->isCopyNode() ) + if ( QString(getEngine()->Name()) == QString(aCB->getCopyNode()->Name()) ) + aCB->setCopyNode( 0 ); getEngine()->destroy(); - if (myCoupled) delete myCoupled; + if (myCoupled) + delete myCoupled; + delete this; aCanvas->update(); @@ -138,12 +141,12 @@ void SUPERVGUI_CanvasStartNode::addOutputPort() void SUPERVGUI_CanvasStartNode::pastePort() { + SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard(); SUPERVGUI_CanvasNode::pastePort(); - if (getMain()->getCopyPort()->IsInput() //paste input port - && - getEngine()->IsLoop()) + if ( aCB->getCopyPort()->IsInput() && getEngine()->IsLoop() ) merge(); - if (myCoupled) myCoupled->merge(); + if ( myCoupled ) + myCoupled->merge(); } //===================================================================== diff --git a/src/SUPERVGUI/SUPERVGUI_CanvasLink.cxx b/src/SUPERVGUI/SUPERVGUI_CanvasLink.cxx index 08ad4a6..5ae3abf 100644 --- a/src/SUPERVGUI/SUPERVGUI_CanvasLink.cxx +++ b/src/SUPERVGUI/SUPERVGUI_CanvasLink.cxx @@ -367,20 +367,24 @@ bool SUPERVGUI_CanvasLinkBuilder::canCreateEngine(SUPERVGUI_CanvasPort* thePort) (aOutKind == SUPERV::DataStreamParameter && aInKind != SUPERV::DataStreamParameter)) return false; - // connect gate port with gate or inline port - if (aInKind == SUPERV::GateParameter || aOutKind == SUPERV::GateParameter) { - if (aInKind != aOutKind && - aInKind != SUPERV::InLineParameter && - aOutKind != SUPERV::InLineParameter) + // asv : 15.12.04 : NOT allow to connect Gate-to-InLine --> it does not make sence! + // Out Gate port can be connected only to In Gate port + if ( aOutKind == SUPERV::GateParameter && aInKind != SUPERV::GateParameter ) + return false; + + // In Gate can be connected to (receive links from) Gate port and InLine ports (important for Switch nodes) + if ( aInKind == SUPERV::GateParameter && aOutKind != SUPERV::GateParameter && aOutKind != SUPERV::InLineParameter ) return false; - } // control if port is already linked except for input port of end switch node if (!(aInKind == SUPERV::EndSwitchParameter || aInPort->getEngine()->Node()->Kind() == SUPERV::EndSwitchNode)) { - if (aInPort->getEngine()->IsLinked()) + // asv : 15.12.04 : PAL7374, p.2.2 "Bugs and Improvements": multiple links into Gate port + // for InGate it's OK to accept more than 1 link + if ( aInPort->getEngine()->IsLinked() && aInKind != SUPERV::GateParameter ) return false; } + result = true; } return result; diff --git a/src/SUPERVGUI/SUPERVGUI_CanvasNode.cxx b/src/SUPERVGUI/SUPERVGUI_CanvasNode.cxx index a8f9e6c..997e51a 100644 --- a/src/SUPERVGUI/SUPERVGUI_CanvasNode.cxx +++ b/src/SUPERVGUI/SUPERVGUI_CanvasNode.cxx @@ -10,6 +10,7 @@ using namespace std; #include "SUPERVGUI_CanvasNode.h" #include "SUPERVGUI_CanvasNodePrs.h" #include "SUPERVGUI_CanvasPort.h" +#include "SUPERVGUI_Clipboard.h" #include "SUPERVGUI_Main.h" #include "SUPERVGUI.h" #include "SUPERVGUI_BrowseNodeDlg.h" @@ -189,8 +190,8 @@ QPopupMenu* SUPERVGUI_CanvasNode::getPopupMenu(QWidget* theParent) // Paste Port functionality int aPasteItem = popup->insertItem(tr("ITM_PASTE_PORT"), this, SLOT(pastePort())); - if ( SUPERV_isNull(myMain->getCopyPort()) || !(myMain->getCopyPort()) || - (type == SUPERV::LoopNode && !myMain->getCopyPort()->IsInput()) ) + SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard(); + if ( !aCB->isCopyPort() || (type == SUPERV::LoopNode && !aCB->getCopyPort()->IsInput()) ) popup->setItemEnabled( aPasteItem, false ); } } @@ -366,15 +367,16 @@ void SUPERVGUI_CanvasNode::remove() { //set myCopyPort from Main object to empty if engine of this port is deleted //check if any port of this deleted node has been copied - if (!SUPERV_isNull(getMain()->getCopyPort()) || getMain()->getCopyPort()) - if ((QString(myNode->Name())).compare(QString(getMain()->getCopyPort()->Node()->Name())) == 0) - getMain()->setCopyPort(NULL); + SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard(); + if ( aCB->isCopyPort() ) + if ( QString(myNode->Name()) == QString(aCB->getCopyPort()->Node()->Name()) ) + aCB->setCopyPort( 0 ); //set myCopyNode from Main object to empty if engine of this node is deleted //check if myCopyNode and this node engine is equal - if (!SUPERV_isNull(getMain()->getCopyNode()) || getMain()->getCopyNode()) - if ((QString(myNode->Name())).compare(QString(getMain()->getCopyNode()->Name())) == 0) - getMain()->setCopyNode(NULL); + if ( aCB->isCopyNode() ) + if ( QString(myNode->Name()) == QString(aCB->getCopyNode()->Name()) ) + aCB->setCopyNode( 0 ); Trace("SUPERVGUI_CanvasNode::remove"); SUPERVGUI_Canvas* aCanvas = myMain->getCanvas(); @@ -386,13 +388,12 @@ void SUPERVGUI_CanvasNode::remove() { void SUPERVGUI_CanvasNode::copy() { Trace("SUPERVGUI_CanvasNode::copy()"); - //MESSAGE(" -> SUPERVGUI_CanvasNode::copy()"); - if (getNodeType() == SUPERV::EndLoopNode - || - getNodeType() == SUPERV::EndSwitchNode) - getMain()->setCopyNode(SUPERV::CNode::_duplicate(SUPERV::GNode::_narrow(getEngine())->Coupled())); + SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard(); + const int aKind = getNodeType(); + if ( aKind == SUPERV::EndLoopNode || aKind == SUPERV::EndSwitchNode ) + aCB->setCopyNode( SUPERV::CNode::_duplicate(SUPERV::GNode::_narrow(getEngine())->Coupled()) ); else - getMain()->setCopyNode(SUPERV::CNode::_duplicate(getEngine())); + aCB->setCopyNode( SUPERV::CNode::_duplicate( getEngine() ) ); } void SUPERVGUI_CanvasNode::suspendResume() { @@ -640,37 +641,11 @@ void SUPERVGUI_CanvasNode::editFunction() { } } -void SUPERVGUI_CanvasNode::pastePort() -{ - //MESSAGE(" -> SUPERVGUI_CanvasNode::pastePort()"); - - SUPERV_Port aPort = myMain->getCopyPort(); - if (!SUPERV_isNull(aPort)) { - SUPERV_INode aNode = getInlineNode(); - if (!SUPERV_isNull(aNode)) { - QString aName = aPort->Name(); - QString aType = aPort->Type(); - SUPERV_Port aPastePort; - if (aPort->IsInput()) { - //check if port with such name is alredy exists - QStringList aNames = getPortsNamesIN(aNode, true); - if (aNames.contains(aName)) - QMessageBox::warning( QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_PORT_EXIST") ); - else - aPastePort = aNode->InPort(aName.latin1(), aType.latin1()); - } - else { - //check if port with such name is already exists - QStringList aNames = getPortsNamesIN(aNode, false); - if (aNames.contains(aName)) - QMessageBox::warning( QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_PORT_EXIST") ); - else - aPastePort = aNode->OutPort(aName.latin1(), aType.latin1()); - } - if (!SUPERV_isNull(aPastePort)) - createPort(aPastePort.in()); - } - } +/** + * Called on "Paste port" command of popup menu + */ +void SUPERVGUI_CanvasNode::pastePort() { + SUPERVGUI_Clipboard::getClipboard()->pastePort( this ); } /** diff --git a/src/SUPERVGUI/SUPERVGUI_CanvasNode.h b/src/SUPERVGUI/SUPERVGUI_CanvasNode.h index ae25e0e..acead4e 100644 --- a/src/SUPERVGUI/SUPERVGUI_CanvasNode.h +++ b/src/SUPERVGUI/SUPERVGUI_CanvasNode.h @@ -19,6 +19,7 @@ class SUPERVGUI_CanvasNodePrs; class SUPERVGUI_CanvasNode : public QObject { friend class SUPERVGUI_ManagePortsDlg; + friend class SUPERVGUI_Clipboard; Q_OBJECT diff --git a/src/SUPERVGUI/SUPERVGUI_CanvasPort.cxx b/src/SUPERVGUI/SUPERVGUI_CanvasPort.cxx index 6a10fa2..39577fc 100644 --- a/src/SUPERVGUI/SUPERVGUI_CanvasPort.cxx +++ b/src/SUPERVGUI/SUPERVGUI_CanvasPort.cxx @@ -11,6 +11,7 @@ using namespace std; #include "SUPERVGUI_CanvasNode.h" #include "SUPERVGUI_CanvasLink.h" #include "SUPERVGUI_CanvasNodePrs.h" +#include "SUPERVGUI_Clipboard.h" #include "SUPERVGUI_Main.h" #include "SUPERVGUI.h" #include "SUPERVGUI_BrowseNodeDlg.h" @@ -127,13 +128,12 @@ void SUPERVGUI_CanvasPort::remove() { //set myCopyPort from Main object to empty if engine of this port is deleted //check if myCopyPort and this port engine is equal - if (!SUPERV_isNull(getMain()->getCopyPort()) || getMain()->getCopyPort()) - if ((QString(myPort->Node()->Name())).compare(QString(getMain()->getCopyPort()->Node()->Name())) == 0 - && - (QString(myPort->Name())).compare(QString(getMain()->getCopyPort()->Name())) == 0 - && - myPort->IsInput() == getMain()->getCopyPort()->IsInput()) - getMain()->setCopyPort(NULL); + SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard(); + if ( aCB->isCopyPort() ) + if ( QString(myPort->Node()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) && + QString(myPort->Name()) == QString(aCB->getCopyPort()->Name()) && + myPort->IsInput() == aCB->getCopyPort()->IsInput() ) + aCB->setCopyPort( 0 ); Trace("SUPERVGUI_CanvasPort::remove"); myPort->destroy(); @@ -181,8 +181,8 @@ void SUPERVGUI_CanvasPort::browse() void SUPERVGUI_CanvasPort::copy() { - //MESSAGE(" -> SUPERVGUI_CanvasPort::copy()"); - getMain()->setCopyPort(SUPERV::Port::_duplicate(getEngine())); + SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard(); + aCB->setCopyPort(SUPERV::Port::_duplicate(getEngine())); } //*********************************************************** diff --git a/src/SUPERVGUI/SUPERVGUI_CanvasView.cxx b/src/SUPERVGUI/SUPERVGUI_CanvasView.cxx index 465d9f1..d86b9cc 100644 --- a/src/SUPERVGUI/SUPERVGUI_CanvasView.cxx +++ b/src/SUPERVGUI/SUPERVGUI_CanvasView.cxx @@ -16,6 +16,7 @@ using namespace std; #include "SUPERVGUI_CanvasPort.h" #include "SUPERVGUI_CanvasLink.h" #include "SUPERVGUI_CanvasNodePrs.h" +#include "SUPERVGUI_Clipboard.h" #include "QAD_Config.h" #include "QAD_MessageBox.h" @@ -101,7 +102,8 @@ SUPERVGUI_CanvasView::SUPERVGUI_CanvasView(SUPERVGUI_Canvas* theCanvas, SUPERVGU myPopup->insertItem(tr("MSG_ADD_NODE"), myMain, SLOT(addNode())); // Paste Node functionality - myPasteNodeItem = myPopup->insertItem(tr("ITM_PASTE_NODE"), myMain, SLOT(pasteNode())); + SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard(); + myPasteNodeItem = myPopup->insertItem(tr("ITM_PASTE_NODE"), aCB, SLOT(pasteNode())); myPopup->insertItem(tr("MSG_INS_FILE"), myMain, SLOT(insertFile())); myPopup->insertSeparator(); @@ -222,10 +224,8 @@ void SUPERVGUI_CanvasView::contentsMousePressEvent(QMouseEvent* theEvent) myPopup->setItemEnabled(myAddStudyItem, !myMain->isFromStudy()); // Paste Node functionality - if (SUPERV_isNull(myMain->getCopyNode()) || !(myMain->getCopyNode())) - myPopup->setItemEnabled(myPasteNodeItem, false); - else - myPopup->setItemEnabled(myPasteNodeItem, true); + SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard(); + myPopup->setItemEnabled(myPasteNodeItem, aCB->isCopyNode() ); myMain->showPopup(myPopup, theEvent); return; } diff --git a/src/SUPERVGUI/SUPERVGUI_Clipboard.cxx b/src/SUPERVGUI/SUPERVGUI_Clipboard.cxx new file mode 100644 index 0000000..6b2f500 --- /dev/null +++ b/src/SUPERVGUI/SUPERVGUI_Clipboard.cxx @@ -0,0 +1,309 @@ +// SUPERV SUPERVGUI : GUI for Supervisor component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SUPERVGUI_Clipboard.cxx +// Author : Alexander SLADKOV +// Module : SUPERV + + +#include "SUPERVGUI_Clipboard.h" +#include "SUPERVGUI_CanvasNode.h" +#include "SUPERVGUI.h" + + +SUPERVGUI_Clipboard* SUPERVGUI_Clipboard::myCB = 0; + + +/** + * Compute the next valid name for a Python function (add "_N" if a function with given name already exists) + */ +QString getNewName( QStringList& allNames, const QString& oldName ) { + QString newName; + int id = 1; //increment index + newName = oldName + QString("_") + QString::number( id ); + while ( allNames.contains( newName ) ) + newName = oldName + QString("_") + QString::number( ++id ); + + return newName; +} + +/** + * Replaces "def*origName*" string with "def*newName*" string + */ +bool replaceName( SUPERV::ListOfStrings_var& theFunc, const QString& origName, const QString& newName ) { + // asv : 30.12.04 : it's a mistake to replace all function_name-s in all function_strings. + // must be only in "def XXX():", with "do-while" I want to skip all empty and comment lines.. + int i( 0 ), index( -1 ); + do { + QString aLine( theFunc[i] ); + index = aLine.find(origName); + if ( index >= 0 && aLine.startsWith( "def" ) ) { // looking for "def*origName*" + theFunc[i] = aLine.replace( index, origName.length(), newName ).latin1(); + return true; + } + i++; + } + while ( i < theFunc->length() ); + return false; +} + +/** + * "Copies" all ports from fromNode to toNode: creates the sames ports in toNode in fact + */ +void copyPorts( const SUPERV::CNode_var& fromNode, const SUPERV::INode_var& toNode ) { + if ( CORBA::is_nil( fromNode ) || CORBA::is_nil( toNode ) ) + return; + SUPERV::ListOfPorts_var aPList = fromNode->Ports(); + QString aName, aType; + for (int i = 0; i < aPList->length(); i++) { + aName = aPList[i].in()->Name(); + aType = aPList[i].in()->Type(); + if ( aPList[i].in()->IsInput() ) + toNode->InPort( aName.latin1(), aType.latin1() ); + else + toNode->OutPort( aName.latin1(), aType.latin1() ); + } +} + +/** + * Called on Paste Node command. Inserts a new node to the dataflow equal to the copied node. + * For InLine nodes the Python function name is changed ("_N" added). + */ +void SUPERVGUI_Clipboard::pasteNode() { + Trace("SUPERVGUI_Main::pasteNode"); + SUPERV::CNode_var aNode = getCopyNode(); + if ( !CORBA::is_nil( aNode ) ) { + + //collect all python functions names of allready exist InLine nodes + //in QStringList for automatic change of function's name on Paste of InLine node + QStringList aFuncNames; + SUPERV::Graph_var dataflow = Supervision.getMain()->getDataflow(); + SUPERV::ListOfNodes_var nodes = dataflow->Nodes(); + //InLine nodes + for(int i = 0; i < nodes->INodes.length(); i++) + aFuncNames.append(nodes->INodes[i]->PyFuncName()); + //Loop nodes + for(int i = 0; i < nodes->LNodes.length(); i++) { + aFuncNames.append(nodes->LNodes[i]->PyInitName()); + aFuncNames.append(nodes->LNodes[i]->PyMoreName()); + aFuncNames.append(nodes->LNodes[i]->PyNextName()); + } + //Switch nodes + for(int i = 0; i < nodes->SNodes.length(); i++) + aFuncNames.append(nodes->SNodes[i]->PyFuncName()); + //GOTO nodes + for(int i = 0; i < nodes->GNodes.length(); i++) + aFuncNames.append(nodes->GNodes[i]->PyFuncName()); + + int id, fid; + QString aOriginalName; + + // automatic change of function_name and function_strings ( +"_N" ) + QString aFName, aInitFName, aMoreFName, aNextFName; + SUPERV::ListOfStrings_var aFunc, aInitFunc, aMoreFunc, aNextFunc; + + const int aKind = aNode->Kind(); + + if ( aKind == SUPERV::InLineNode || aKind == SUPERV::GOTONode || aKind == SUPERV::SwitchNode ) { + // "fix" Main function_name and Main function_strings + aOriginalName = SUPERV::INode::_narrow(aNode)->PyFuncName(); + if ( !aOriginalName.isEmpty() ) { + aFName = getNewName( aFuncNames, aOriginalName ); + aFunc = SUPERV::INode::_narrow(aNode)->PyFunction(); + replaceName( aFunc, aOriginalName, aFName ); + } + } + else if (aNode->Kind() == SUPERV::LoopNode) { + + // "fix" Init function_name and Init function_strings + aOriginalName = SUPERV::LNode::_narrow(aNode)->PyInitName(); + if (!aOriginalName.isEmpty()) { + aInitFName = getNewName( aFuncNames, aOriginalName ); + aInitFunc = SUPERV::LNode::_narrow(aNode)->PyInit(); + replaceName( aInitFunc, aOriginalName, aInitFName ); + } + + // "fix" More function_name and More function_strings + aOriginalName = SUPERV::LNode::_narrow(aNode)->PyMoreName(); + if (!aOriginalName.isEmpty()) { + aMoreFName = getNewName( aFuncNames, aOriginalName ); + aMoreFunc = SUPERV::LNode::_narrow(aNode)->PyMore(); + replaceName( aMoreFunc, aOriginalName, aMoreFName ); + } + + // "fix" Next function_name and Next function_strings + aOriginalName = SUPERV::LNode::_narrow(aNode)->PyNextName(); + if (!aOriginalName.isEmpty()) { + aNextFName = getNewName( aFuncNames, aOriginalName ); + aNextFunc = SUPERV::LNode::_narrow(aNode)->PyNext(); + replaceName( aNextFunc, aOriginalName, aNextFName ); + } + } + + int cx, cy; + //2.8 point of improvements: Adding node to graph window with taking into account zoom factor + SUPERVGUI_CanvasView* aCanvasView = Supervision.getMain()->getCanvasView(); + QWMatrix aWM = aCanvasView->worldMatrix(); + switch (aNode->Kind()) { + case SUPERV::FactoryNode : + { + SUPERV::FNode_var aFNode = dataflow->FNode( SUPERV::FNode::_narrow(aNode)->GetComponentName(), + SUPERV::FNode::_narrow(aNode)->GetInterfaceName(), + *SUPERV::FNode::_narrow(aNode)->Service() ); + if (CORBA::is_nil(aFNode)) { + QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); + return; + } + + SUPERV::INode_var aDummyEndNode; + Supervision.getBrowser()->addNode(SUPERV::CNode::_narrow(aFNode), aDummyEndNode, myXCopyNode, myYCopyNode); + } + break; + case SUPERV::ComputingNode : + { + SUPERV::CNode_var aCNode = dataflow->CNode(*SUPERV::CNode::_narrow(aNode)->Service()); + if (CORBA::is_nil(aCNode)) { + QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); + return; + } + + SUPERV::INode_var aDummyEndNode; + Supervision.getBrowser()->addNode(aCNode, aDummyEndNode, myXCopyNode, myYCopyNode); + } + break; + case SUPERV::InLineNode : + { + SUPERV::INode_var aINode = dataflow->INode( aFName, aFunc ); + + if (CORBA::is_nil(aINode)) { + QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); + return; + } + copyPorts( aNode, aINode ); + + SUPERV::INode_var aDummyEndNode; + Supervision.getBrowser()->addNode(SUPERV::CNode::_narrow(aINode), aDummyEndNode, myXCopyNode, myYCopyNode); + } + break; + case SUPERV::LoopNode : + { + SUPERV::INode_var aEndNode; + SUPERV::LNode_var aStartNode = dataflow->LNode(aInitFName, aInitFunc, aMoreFName, aMoreFunc, aNextFName, aNextFunc, aEndNode); + if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) { + QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); + return; + } + copyPorts( aNode, SUPERV::INode::_narrow( aStartNode ) ); + + Supervision.getBrowser()->addNode(SUPERV::CNode::_narrow(aStartNode), aEndNode, myXCopyNode, myYCopyNode); + } + break; + case SUPERV::SwitchNode : + { + SUPERV::INode_var aEndNode; + SUPERV::SNode_var aStartNode = dataflow->SNode(aFName, aFunc, aEndNode); + if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) { + QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); + return; + } + copyPorts( aNode, SUPERV::INode::_narrow( aStartNode ) ); + SUPERV::INode_var aNodeEnd = SUPERV::SNode::_narrow(aNode)->Coupled(); + copyPorts( SUPERV::CNode::_narrow( aNodeEnd ), aEndNode ); + + Supervision.getBrowser()->addNode(SUPERV::CNode::_narrow(aStartNode), aEndNode, myXCopyNode, myYCopyNode); + } + break; + case SUPERV::GOTONode : + { + SUPERV::GNode_var aGNode = dataflow->GNode(aFName, aFunc, ""); + if (CORBA::is_nil(aGNode)) { + QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); + return; + } + copyPorts( aNode, SUPERV::INode::_narrow( aGNode ) ); + + SUPERV::INode_var aDummyEndNode; + Supervision.getBrowser()->addNode(SUPERV::CNode::_narrow(aGNode), aDummyEndNode, myXCopyNode, myYCopyNode); + } + break; + case SUPERV::MacroNode : + { + /* to implement in the future */ + /* + //get SubGraph from MacroNode + SUPERV::Graph_var aMacro = SUPERV::Graph::_narrow(aNode); + SUPERV::Graph_var aGraph; + if (aMacro->IsStreamMacro()) + aGraph = aMacro->StreamObjRef(); + else + aGraph = aMacro->FlowObjRef(); + SUPERV::Graph_var aMacroNode = dataflow->GraphMNode(aGraph); + + if (CORBA::is_nil(aMacroNode)) { + QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); + return; + } + + SUPERV::INode_var aDummyEndNode; + Supervision.getBrowser()->addNode(SUPERV::CNode::_narrow(aMacroNode), aDummyEndNode, myXCopyNode, myYCopyNode); + */ + } + break; + } + } +} + + +/** + * Called from CanvasNode on "Paste port" command of popup menu + */ +void SUPERVGUI_Clipboard::pastePort( SUPERVGUI_CanvasNode* node ) +{ + SUPERV::Port_var aPort = getCopyPort(); + if ( !CORBA::is_nil(aPort) ) { + SUPERV::INode_var aNode = node->getInlineNode(); + if (!CORBA::is_nil(aNode)) { + QString aName = aPort->Name(); + QString aType = aPort->Type(); + SUPERV::Port_var aPastePort; + if (aPort->IsInput()) { + //check if port with such name is alredy exists + QStringList aNames = node->getPortsNamesIN(aNode, true); + if (aNames.contains(aName)) + QMessageBox::warning( QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_PORT_EXIST") ); + else + aPastePort = aNode->InPort(aName.latin1(), aType.latin1()); + } + else { + //check if port with such name is already exists + QStringList aNames = node->getPortsNamesIN(aNode, false); + if (aNames.contains(aName)) + QMessageBox::warning( QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_PORT_EXIST") ); + else + aPastePort = aNode->OutPort(aName.latin1(), aType.latin1()); + } + if ( !CORBA::is_nil(aPastePort) ) + node->createPort( aPastePort.in() ); + } + } +} diff --git a/src/SUPERVGUI/SUPERVGUI_Clipboard.h b/src/SUPERVGUI/SUPERVGUI_Clipboard.h new file mode 100644 index 0000000..b40e979 --- /dev/null +++ b/src/SUPERVGUI/SUPERVGUI_Clipboard.h @@ -0,0 +1,77 @@ +// SUPERV SUPERVGUI : GUI for Supervisor component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SUPERVGUI_Clipboard.h +// Author : Alexander SLADKOV +// Module : SUPERV + +#ifndef SUPERVGUI_Clipboard_H +#define SUPERVGUI_Clipboard_H + +#include + +#include "utilities.h" +#include "SALOME_LifeCycleCORBA.hxx" +#include CORBA_CLIENT_HEADER(SUPERV) + +class SUPERVGUI_CanvasNode; + +class SUPERVGUI_Clipboard : public QObject { + +Q_OBJECT + +protected: + // constructor made protected. Access via getClipboard() member function. + SUPERVGUI_Clipboard(); + virtual ~SUPERVGUI_Clipboard(); + +public: + + static SUPERVGUI_Clipboard* getClipboard() { + if ( !myCB ) + myCB = new SUPERVGUI_Clipboard(); + return myCB; + } + + bool isCopyPort() const { return ( myCopyPort && !CORBA::is_nil( myCopyPort ) ); } + SUPERV::Port_var getCopyPort() const { return myCopyPort; } + void setCopyPort( SUPERV::Port_var theObj ) { myCopyPort = theObj; } + + bool isCopyNode() const { return ( myCopyNode && !CORBA::is_nil( myCopyNode ) ); } + SUPERV::CNode_var getCopyNode() const { return myCopyNode; } + void setCopyNode( SUPERV::CNode_var theObj ) { myCopyNode = theObj; } + +public slots: + void pasteNode(); + void pastePort( SUPERVGUI_CanvasNode* node ); + +private: + static SUPERVGUI_Clipboard* myCB; + + SUPERV::Port_var myCopyPort; + SUPERV::CNode_var myCopyNode; + int myXCopyNode; + int myYCopyNode; +}; + +#endif diff --git a/src/SUPERVGUI/SUPERVGUI_Main.cxx b/src/SUPERVGUI/SUPERVGUI_Main.cxx index fb305bc..e454143 100644 --- a/src/SUPERVGUI/SUPERVGUI_Main.cxx +++ b/src/SUPERVGUI/SUPERVGUI_Main.cxx @@ -70,10 +70,6 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th myGUIEventLoopFinished( true ) { Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)"); - myCopyPort = 0; - myCopyNode = 0; - myXCopyNode = 0; - myYCopyNode = 0; theParent->setViewWidget(this); dataflow = theDataFlow; if (SUPERV_isNull(dataflow)) { @@ -614,288 +610,6 @@ void SUPERVGUI_Main::addNode() { Supervision.getBrowser()->choose(); } -void SUPERVGUI_Main::pasteNode() { - Trace("SUPERVGUI_Main::pasteNode"); - //MESSAGE(" -> SUPERVGUI_Main::pasteNode()"); - SUPERV_CNode aNode = getCopyNode(); - if (!SUPERV_isNull(aNode)) { - - //collect all python functions names of allready exist InLine nodes - //in QStringList for automatic change of function's name on Paste of InLine node - QStringList aFuncNames; - SUPERV_Nodes nodes = dataflow->Nodes(); - //InLine nodes - for(int i = 0; i < nodes->INodes.length(); i++) - aFuncNames.append(nodes->INodes[i]->PyFuncName()); - //Loop nodes - for(int i = 0; i < nodes->LNodes.length(); i++) { - aFuncNames.append(nodes->LNodes[i]->PyInitName()); - aFuncNames.append(nodes->LNodes[i]->PyMoreName()); - aFuncNames.append(nodes->LNodes[i]->PyNextName()); - } - //Switch nodes - for(int i = 0; i < nodes->SNodes.length(); i++) - aFuncNames.append(nodes->SNodes[i]->PyFuncName()); - //GOTO nodes - for(int i = 0; i < nodes->GNodes.length(); i++) - aFuncNames.append(nodes->GNodes[i]->PyFuncName()); - - int id, fid; - QString aOriginalName; - //automatic change of function's name on Paste of InLine node - QString aFName; - SUPERV::ListOfStrings aFunc; - if (aNode->Kind() == SUPERV::InLineNode - || - aNode->Kind() == SUPERV::GOTONode - || - aNode->Kind() == SUPERV::SwitchNode) { - //original name of the function - aOriginalName = SUPERV::INode::_narrow(aNode)->PyFuncName(); - if (!aOriginalName.isEmpty()) { - id = 1; //increment index - aFName = aOriginalName + QString("_") + QString::number(id); - while (aFuncNames.contains(aFName)) - aFName = aOriginalName + QString("_") + QString::number(id++); - - //correct python function - aFunc = *SUPERV::INode::_narrow(aNode)->PyFunction(); - for (int i=0; i < aFunc.length(); i++) { - fid = QString(aFunc[i]).find(aOriginalName); - if (fid >= 0) - aFunc[i] = QString(aFunc[i]).replace(fid, aOriginalName.length(), aFName); - } - } - } - QString aInitFName, aMoreFName, aNextFName; - SUPERV::ListOfStrings aInitFunc, aMoreFunc, aNextFunc; - if (aNode->Kind() == SUPERV::LoopNode) { - //original name of the Init function - aOriginalName = SUPERV::LNode::_narrow(aNode)->PyInitName(); - if (!aOriginalName.isEmpty()) { - id = 1; //increment index - aInitFName = aOriginalName + QString("_") + QString::number(id); - while (aFuncNames.contains(aInitFName)) - aInitFName = aOriginalName + QString("_") + QString::number(id++); - - //correct python Init function - aInitFunc = *SUPERV::LNode::_narrow(aNode)->PyInit(); - for (int i=0; i < aInitFunc.length(); i++) { - fid = QString(aInitFunc[i]).find(aOriginalName); - if (fid >= 0) - aInitFunc[i] = QString(aInitFunc[i]).replace(fid, aOriginalName.length(), aInitFName); - } - } - - //original name of the More function - aOriginalName = SUPERV::LNode::_narrow(aNode)->PyMoreName(); - if (!aOriginalName.isEmpty()) { - id = 1; //increment index - aMoreFName = aOriginalName + QString("_") + QString::number(id); - while (aFuncNames.contains(aMoreFName)) - aMoreFName = aOriginalName + QString("_") + QString::number(id++); - - //correct python More function - aMoreFunc = *SUPERV::LNode::_narrow(aNode)->PyMore(); - for (int i=0; i < aMoreFunc.length(); i++) { - fid = QString(aMoreFunc[i]).find(aOriginalName); - if (fid >= 0) - aMoreFunc[i] = QString(aMoreFunc[i]).replace(fid, aOriginalName.length(), aMoreFName); - } - } - - //original name of the Next function - aOriginalName = SUPERV::LNode::_narrow(aNode)->PyNextName(); - if (!aOriginalName.isEmpty()) { - id = 1; //increment index - aNextFName = aOriginalName + QString("_") + QString::number(id); - while (aFuncNames.contains(aNextFName)) - aNextFName = aOriginalName + QString("_") + QString::number(id++); - - //correct python Init function - aNextFunc = *SUPERV::LNode::_narrow(aNode)->PyNext(); - for (int i=0; i < aNextFunc.length(); i++) { - fid = QString(aNextFunc[i]).find(aOriginalName); - if (fid >= 0) - aNextFunc[i] = QString(aNextFunc[i]).replace(fid, aOriginalName.length(), aNextFName); - } - } - } - - int cx, cy; - //2.8 point of improvements: Adding node to graph window with taking into account zoom factor - QWMatrix aWM = myCanvasView->worldMatrix(); - switch (aNode->Kind()) { - case 0: // Factory Node - { - SUPERV_FNode aFNode = dataflow->FNode(SUPERV::FNode::_narrow(aNode)->GetComponentName(), - SUPERV::FNode::_narrow(aNode)->GetInterfaceName(), - *SUPERV::FNode::_narrow(aNode)->Service()); - if (SUPERV_isNull(aFNode)) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); - return; - } - - SUPERV_INode aDummyEndNode; - Supervision.getBrowser()->addNode(SUPERV::CNode::_narrow(aFNode), aDummyEndNode, myXCopyNode, myYCopyNode); - } - break; - case 2: // Computing Node - { - SUPERV_CNode aCNode = dataflow->CNode(*SUPERV::CNode::_narrow(aNode)->Service()); - if (SUPERV_isNull(aCNode)) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); - return; - } - - SUPERV_INode aDummyEndNode; - Supervision.getBrowser()->addNode(aCNode, aDummyEndNode, myXCopyNode, myYCopyNode); - } - break; - case 3: //InLineNode - { - SUPERV_INode aINode = dataflow->INode(aFName, - aFunc); - - if (SUPERV_isNull(aINode)) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); - return; - } - //add all ports of coping node to the new node, which will be paste - SUPERV_Ports aPList = aNode->Ports(); - QString aName, aType; - for (int i = 0; i < aPList->length(); i++) { - aName = aPList[i].in()->Name(); - aType = aPList[i].in()->Type(); - if (aPList[i].in()->IsInput()) - aINode->InPort(aName.latin1(), aType.latin1()); - else - aINode->OutPort(aName.latin1(), aType.latin1()); - } - - SUPERV_INode aDummyEndNode; - Supervision.getBrowser()->addNode(SUPERV::CNode::_narrow(aINode), aDummyEndNode, myXCopyNode, myYCopyNode); - } - break; - case 4: //LoopNode - { - SUPERV_INode aEndNode; - SUPERV_LNode aStartNode = dataflow->LNode(aInitFName, - aInitFunc, - aMoreFName, - aMoreFunc, - aNextFName, - aNextFunc, - aEndNode); - if (SUPERV_isNull(aStartNode) || SUPERV_isNull(aEndNode)) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); - return; - } - //add all ports of coping node to the new node, which will be paste - SUPERV_Ports aPList = aNode->Ports(); - QString aName, aType; - for (int i = 0; i < aPList->length(); i++) { - aName = aPList[i].in()->Name(); - aType = aPList[i].in()->Type(); - if (aPList[i].in()->IsInput()) - aStartNode->InPort(aName.latin1(), aType.latin1()); - else - aStartNode->OutPort(aName.latin1(), aType.latin1()); - } - - Supervision.getBrowser()->addNode(SUPERV::CNode::_narrow(aStartNode), aEndNode, myXCopyNode, myYCopyNode); - } - break; - case 6: //SwitchNode - { - SUPERV_INode aEndNode; - SUPERV_SNode aStartNode = dataflow->SNode(aFName, - aFunc, - aEndNode); - if (SUPERV_isNull(aStartNode) || SUPERV_isNull(aEndNode)) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); - return; - } - //add all ports of coping start switch node to the new start node, which will be paste - SUPERV_Ports aPList = aNode->Ports(); - QString aName, aType; - for (int i = 0; i < aPList->length(); i++) { - aName = aPList[i].in()->Name(); - aType = aPList[i].in()->Type(); - if (aPList[i].in()->IsInput()) - aStartNode->InPort(aName.latin1(), aType.latin1()); - else - aStartNode->OutPort(aName.latin1(), aType.latin1()); - } - //add all ports of coping end switch node to the new end node, which will be paste - SUPERV_INode aNodeEnd = SUPERV::SNode::_narrow(aNode)->Coupled(); - if (!SUPERV_isNull(aNodeEnd)) { - aPList = aNodeEnd->Ports(); - for (int i = 0; i < aPList->length(); i++) { - //createPort(aPList[i].in()); - aName = aPList[i].in()->Name(); - aType = aPList[i].in()->Type(); - if (aPList[i].in()->IsInput()) - aEndNode->InPort(aName.latin1(), aType.latin1()); - else - aEndNode->OutPort(aName.latin1(), aType.latin1()); - } - } - - Supervision.getBrowser()->addNode(SUPERV::CNode::_narrow(aStartNode), aEndNode, myXCopyNode, myYCopyNode); - } - break; - case 8: //GotoNode - { - SUPERV_GNode aGNode = dataflow->GNode(aFName, - aFunc, ""); - if (SUPERV_isNull(aGNode)) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); - return; - } - //add all ports of coping node to the new node, which will be paste - SUPERV_Ports aPList = aNode->Ports(); - QString aName, aType; - for (int i = 0; i < aPList->length(); i++) { - aName = aPList[i].in()->Name(); - aType = aPList[i].in()->Type(); - if (aPList[i].in()->IsInput()) - aGNode->InPort(aName.latin1(), aType.latin1()); - else - aGNode->OutPort(aName.latin1(), aType.latin1()); - } - - SUPERV_INode aDummyEndNode; - Supervision.getBrowser()->addNode(SUPERV::CNode::_narrow(aGNode), aDummyEndNode, myXCopyNode, myYCopyNode); - } - break; - case 10: //MacroNode - { - /* to implement in the future */ - /* - //get SubGraph from MacroNode - SUPERV_Graph aMacro = SUPERV::Graph::_narrow(aNode); - SUPERV_Graph aGraph; - if (aMacro->IsStreamMacro()) - aGraph = aMacro->StreamObjRef(); - else - aGraph = aMacro->FlowObjRef(); - SUPERV_Graph aMacroNode = dataflow->GraphMNode(aGraph); - - if (SUPERV_isNull(aMacroNode)) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); - return; - } - - SUPERV_INode aDummyEndNode; - Supervision.getBrowser()->addNode(SUPERV::CNode::_narrow(aMacroNode), aDummyEndNode, myXCopyNode, myYCopyNode); - */ - } - break; - } - } -} - /** * Add Computation node */ diff --git a/src/SUPERVGUI/SUPERVGUI_Main.h b/src/SUPERVGUI/SUPERVGUI_Main.h index 8ff308e..03f240f 100644 --- a/src/SUPERVGUI/SUPERVGUI_Main.h +++ b/src/SUPERVGUI/SUPERVGUI_Main.h @@ -126,12 +126,6 @@ class SUPERVGUI_Main: public SUPERVGraph_View { bool eventFilter( QObject* o, QEvent* e); - SUPERV_Port getCopyPort() { return myCopyPort; } - void setCopyPort(SUPERV_Port theObj) { myCopyPort = theObj; } - - SUPERV_CNode getCopyNode() { return myCopyNode; } - void setCopyNode(SUPERV_CNode theObj) { myCopyNode = theObj; } - bool IsGUIEventLoopFinished() const { return myGUIEventLoopFinished; } void Editing(); // any Editing operation is to be performed -> @@ -147,7 +141,6 @@ class SUPERVGUI_Main: public SUPERVGraph_View { bool addStudy(); void insertFile(); void addNode(); - void pasteNode(); void changeInformation(); void copy(); @@ -180,11 +173,6 @@ class SUPERVGUI_Main: public SUPERVGraph_View { QAD_ObjectBrowser* objectBrowser; QAD_Message* message; - SUPERV_Port myCopyPort; - SUPERV_CNode myCopyNode; - int myXCopyNode; - int myYCopyNode; - GraphViewType myCurrentView; SUPERVGUI_CanvasArray* myArray; SUPERVGUI_ArrayView* myArrayView;