Version: 9.16.0
SceneCtrlInPortItem.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
21#include "SceneNodeItem.hxx"
22#include "ItemMimeData.hxx"
23
24#include "QtGuiContext.hxx"
25#include "Menus.hxx"
26#include "Message.hxx"
27
28#include <QGraphicsSceneDragDropEvent>
29
30
31//#define _DEVDEBUG_
32#include "YacsTrace.hxx"
33
34using namespace std;
35using namespace YACS::ENGINE;
36using namespace YACS::HMI;
37
38SceneCtrlInPortItem::SceneCtrlInPortItem(QGraphicsScene *scene, SceneItem *parent,
39 QString label)
40 : SceneCtrlPortItem(scene, parent, label)
41{
42 _dragOver = false;
43 setAcceptDrops(true);
44}
45
47{
48}
49
50void SceneCtrlInPortItem::popupMenu(QWidget *caller, const QPoint &globalPos)
51{
53 m.popupMenu(caller, globalPos);
54}
55
56void SceneCtrlInPortItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
57{
58 bool accepted = false;
59 const ItemMimeData *myData = dynamic_cast<const ItemMimeData*>(event->mimeData());
60 if (myData && myData->hasFormat("yacs/subjectOutGate"))
61 {
62 Subject *sub = myData->getSubject();
63 if (sub && dynamic_cast<SubjectNode*>(sub))
64 {
65 event->setAccepted(true);
66 _dragOver = true;
67 QGraphicsItem::update();
68 return;
69 }
70 }
71 event->setAccepted(accepted);
72}
73
74void SceneCtrlInPortItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
75{
76 Q_UNUSED(event);
77 _dragOver = false;
78 QGraphicsItem::update();
79}
80
81void SceneCtrlInPortItem::dropEvent(QGraphicsSceneDragDropEvent *event)
82{
83 Q_UNUSED(event);
84 _dragOver = false;
85 QGraphicsItem::update();
86
87 const ItemMimeData *myData = dynamic_cast<const ItemMimeData*>(event->mimeData());
88 if (!myData) return;
89 if(!myData->hasFormat("yacs/subjectOutGate")) return;
90 Subject *sub = myData->getSubject();
91 if (!sub) return;
93 if (!item) return;
94 SceneNodeItem* outItem = dynamic_cast<SceneNodeItem*>(item);
95 if (!outItem) return;
96
97 Subject *subFrom = outItem->getSubject();
98 if (!this->getParentNode()) return;
99 Subject *subTo = this->getParentNode()->getSubject();
100 SubjectNode* from = dynamic_cast<SubjectNode*>(subFrom);
101 SubjectNode* to = dynamic_cast<SubjectNode*>(subTo);
102 if (from && to)
103 {
104 if (!SubjectNode::tryCreateLink(from, to))
105 Message mess;
106 }
107}
virtual Subject * getSubject(int i=0) const
static QtGuiContext * getQtCurrent()
std::map< YACS::HMI::Subject *, YACS::HMI::SceneItem * > _mapOfSceneItem
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
virtual void popupMenu(QWidget *caller, const QPoint &globalPos)
void dropEvent(QGraphicsSceneDragDropEvent *event)
virtual SceneNodeItem * getParentNode()
static bool tryCreateLink(SubjectNode *subOutNode, SubjectNode *subInNode)