1 // SALOME SUPERVGraph : build Supervisor viewer into desktop
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 : SUPERVGraph_Graph.cxx
25 // Author : Francis KLOSS
29 #include "SUPERVGraph_Graph.h"
31 #include "QAD_Settings.h"
32 #include "QAD_Config.h"
34 #include <qcolordialog.h>
35 #include <qpopupmenu.h>
38 SUPERVGraph_Graph::SUPERVGraph_Graph(QWidget* parent) :
42 installEventFilter(viewport());
43 // viewport()->setBackgroundColor(QColor(165, 255, 176));
45 connect(this, SIGNAL(contentsMoving(int, int)), this, SLOT(Draw(int, int)));
47 popup = new QPopupMenu(viewport());
48 // if (main->isModify()) {
49 // pan = popup->insertItem("Add Node", main, SLOT(addNode()));
50 // pap = popup->insertItem("Add Point", this, SLOT(addPoint()));
51 // pdl = popup->insertItem("Delete Link", this, SLOT(deleteLink()));
52 // pif = popup->insertItem("Insert File", main, SLOT(insertFile()));
53 // pci = popup->insertItem("Change Informations", this, SLOT(changeInformation()));
54 // popup->insertSeparator();
56 // popup->insertItem("Add in Study", main, SLOT(addStudy()));
57 // popup->insertItem("Show Informations", this, SLOT(showInformation()));
58 // popup->insertSeparator();
59 // popup->insertItem("Copy (Read Only)", main, SLOT(copyReading()));
60 // popup->insertItem("Copy (Modifiying)", main, SLOT(copyModifying()));
63 void SUPERVGraph_Graph::sync() {
64 // bool editing = main->getDataflow()->IsEditing();
65 // if (main->isModify()) {
66 // popup->setItemEnabled(pci, editing);
67 // popup->setItemEnabled(pan, editing);
68 // popup->setItemEnabled(pap, editing);
69 // popup->setItemEnabled(pdl, editing);
70 // popup->setItemEnabled(pif, editing);
73 // SUPERVGraph_Node* ihmNode;
74 // QObjectList* ihmList = queryList("SUPERVGraph_Node");
75 // SUPERV_Nodes nodes = main->getDataflow()->Nodes();
76 // int n = nodes->length();
78 // for (int i=0; i<n; i++) {
79 // ihmNode = (SUPERVGraph_Node *)child(nodes[i]->Name(), "SUPERVGraph_Node");
80 // if (ihmNode == NULL) {
81 // ihmNode = new SUPERVGraph_Node(viewport(), main, nodes[i]);
82 // addChild(ihmNode, nodes[i]->X(), nodes[i]->Y());
84 // moveChild(ihmNode, nodes[i]->X(), nodes[i]->Y());
85 // ihmList->removeRef(ihmNode);
90 // QObjectListIt i(*ihmList);
91 // while ((ihmNode=(SUPERVGraph_Node*)i.current()) != 0) {
97 // SUPERVGraph_PortIn* pi;
98 // ihmList = queryList("SUPERVGraph_PortIn");
100 // while ((pi=(SUPERVGraph_PortIn*)i.current()) != 0) {
106 // SUPERVGraph_PortOut* po;
107 // ihmList = queryList("SUPERVGraph_PortOut");
109 // while ((po=(SUPERVGraph_PortOut*)i.current()) != 0) {
118 SUPERVGraph_Graph::~SUPERVGraph_Graph() {
121 bool SUPERVGraph_Graph::eventFilter(QObject* object, QEvent* event) {
122 if ((event->type() == QEvent::Move ) ||
123 (event->type() == QEvent::Paint) ||
124 (event->type() == QEvent::Resize) ) {
127 return(QScrollView::eventFilter(object, event));
130 void SUPERVGraph_Graph::Draw(int x, int y) {
131 QPainter p(viewport());
132 p.eraseRect(viewport()->rect());
133 p.setPen(QPen(Qt::black, 2));
135 // SUPERVGraph_Point* c;
136 // SUPERVGraph_Point* n;
137 // QObjectList* points = queryList("SUPERVGraph_Point");
138 // QObjectListIt i(*points);
139 // while ((c=(SUPERVGraph_Point*)i.current()) != 0) {
143 // p.drawLine(contentsToViewport(QPoint(c->getX()+POINT_SIZE_HALF, c->getY()+POINT_SIZE_HALF)),
144 // contentsToViewport(QPoint(n->getX()+POINT_SIZE_HALF, n->getY()+POINT_SIZE_HALF)) );
150 void SUPERVGraph_Graph::contentsMousePressEvent(QMouseEvent* e) {
151 where = viewportToContents(viewport()->mapFromGlobal(e->globalPos()));
152 // main->showPopup(popup, e);
155 void SUPERVGraph_Graph::contentsMouseReleaseEvent(QMouseEvent* e) {
156 // main->sketchPoint(NULL);
158 if ( e->button() == Qt::RightButton ) {
159 QPopupMenu* popup = createPopup();
161 popup->exec( QCursor::pos() );
169 void SUPERVGraph_Graph::contentsMouseMoveEvent(QMouseEvent* e) {
170 // main->sketchMove();
173 float SUPERVGraph_Graph::distance(int xp, int yp, int xl, int yl, int xn, int yn) {
177 float px = (float)(xp);
178 float py = (float)(yp);
179 float lx = (float)(xl);
180 float ly = (float)(yl);
181 float nx = (float)(xn);
182 float ny = (float)(yn);
212 QPoint SUPERVGraph_Graph::getPoint() {
216 // SUPERVGraph_Point* SUPERVGraph_Graph::findPoint(int x, int y) {
218 // float d = SCROLL_MAX;
219 // SUPERVGraph_Point* t = NULL;
220 // SUPERVGraph_Point* c;
221 // SUPERVGraph_Point* n;
222 // QObjectList* points = queryList("SUPERVGraph_Point");
223 // QObjectListIt i(*points);
225 // while ((c=(SUPERVGraph_Point*)i.current()) != 0) {
229 // m = distance(x, y, c->getX(), c->getY(), n->getX(), n->getY());
240 void SUPERVGraph_Graph::addPoint() {
241 // int x = where.x();
242 // int y = where.y();
243 // SUPERVGraph_Point* p = findPoint(x, y);
245 // QMessageBox::warning(0, "Supervision Error", "No Link to Add a Point");
247 // p->addPoint(x, y, true);
251 void SUPERVGraph_Graph::deleteLink() {
252 // SUPERVGraph_Point* p = findPoint(where.x(), where.y());
254 // QMessageBox::warning(0, "Supervision Error", "No Link to Delete");
256 // SUPERV_Link l = p->getLink();
258 // QMessageBox::warning(0, "Supervision Error", "No Link to Delete");
266 void SUPERVGraph_Graph::showInformation() {
267 // if (Supervision.information(Engines::Node::_narrow(main->getDataflow()), false)) {
272 void SUPERVGraph_Graph::changeInformation() {
273 // if (Supervision.information(Engines::Node::_narrow(main->getDataflow()), true)) {
281 void SUPERVGraph_Graph::onCreatePopup()
284 // if (myPopup->count()<1) {
285 if ( myPopup->count() > 0 )
286 myIDs.append ( myPopup->insertSeparator() );
288 myIDs.append ( id = myPopup->insertItem (tr ("MEN_VP3D_CHANGEBGR")) );
289 QAD_ASSERT ( myPopup->connectItem ( id, this, SLOT(onChangeBackgroundColor())) );
294 void SUPERVGraph_Graph::onChangeBackgroundColor()
296 QColor previousColor = viewport()->backgroundColor();
297 QColor selColor = QColorDialog::getColor ( previousColor, NULL );
298 if ( selColor.isValid() )
299 viewport()->setBackgroundColor( selColor );
301 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed", selColor.red() );
302 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", selColor.green() );
303 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue", selColor.blue() );