OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | List of all members
EditPart Class Reference

#include <EditPart.hh>

Inheritance diagram for EditPart:
Inheritance graph
Collaboration diagram for EditPart:
Collaboration graph

Public Member Functions

 EditPart ()
 
virtual ~EditPart ()
 
void putGarbage (std::set< EditPart * > &trashbag)
 
EditPartparent () const
 
void setParent (EditPart *parent)
 
TTAMachine::MachinePartmodel () const
 
void setModel (TTAMachine::MachinePart *model)
 
Figurefigure () const
 
void setFigure (Figure *figure)
 
EditPartfind (wxPoint point)
 
EditPartfind (const TTAMachine::MachinePart *model)
 
EditPartfindNearest (wxPoint point, const EditPart *exclude=NULL)
 
int findInRange (wxPoint point, float radius, std::vector< EditPart * > &found)
 
bool hasEditPartRecursive (const EditPart *part) const
 
bool selectable () const
 
bool selected () const
 
void setSelectable (bool selectable)
 
void setSelected (bool select)
 
void installEditPolicy (EditPolicy *editpolicy)
 
void addChild (EditPart *child)
 
int childCount () const
 
EditPartchild (unsigned int index) const
 
ComponentCommandperformRequest (Request *request) const
 
bool canHandle (Request *request) const
 

Protected Attributes

EditPartparent_
 Parent of this EditPart.
 
Figurefigure_
 Figure of this EditPart.
 
TTAMachine::MachinePartmodel_
 Machine component corresponding to this EditPart.
 
bool selectable_
 Tells whether the EditPart is selectable or not.
 
bool selected_
 Tells whether the EditPart is selected or not.
 
bool garbageCollected_
 Helper member to prevent improper deletion.
 
std::vector< EditPolicy * > editPolicies_
 List of supported EditPolicies.
 
std::vector< EditPart * > children_
 List of children EditParts.
 

Private Member Functions

EditPartoperator= (EditPart &old)
 Assignment not allowed.
 
 EditPart (EditPart &old)
 Copying not allowed.
 

Static Private Member Functions

static float distance (wxPoint p, wxRect r)
 

Detailed Description

Connects a model object to a graphical object on the canvas.

An EditPart receives Requests generated by user actions and converts them to possible changes in the model (Commands) using its EditPolicies. EditParts can contain other EditParts as children. Every EditPart has a Figure.

Definition at line 60 of file EditPart.hh.

Constructor & Destructor Documentation

◆ EditPart() [1/2]

EditPart::EditPart ( )

The Constructor.

Definition at line 60 of file EditPart.cc.

60 :
61 parent_(NULL), figure_(NULL), model_(NULL), selectable_(
62 false), selected_(false), garbageCollected_(false) {
63}
bool selected_
Tells whether the EditPart is selected or not.
Definition EditPart.hh:99
TTAMachine::MachinePart * model_
Machine component corresponding to this EditPart.
Definition EditPart.hh:95
Figure * figure_
Figure of this EditPart.
Definition EditPart.hh:93
EditPart * parent_
Parent of this EditPart.
Definition EditPart.hh:91
bool garbageCollected_
Helper member to prevent improper deletion.
Definition EditPart.hh:102
bool selectable_
Tells whether the EditPart is selectable or not.
Definition EditPart.hh:97

◆ ~EditPart()

EditPart::~EditPart ( )
virtual

The Destructor.

Note
Do not destruct this object elsewhere than in the RootEditPart destructor! Children "garbage" should be collected before and EditPart is deleted.

Definition at line 72 of file EditPart.cc.

72 {
74 for (unsigned int i = 0; i < editPolicies_.size(); i++) {
75 delete editPolicies_[i];
76 }
77 editPolicies_.clear();
78 delete figure_;
79}
#define assert(condition)
std::vector< EditPolicy * > editPolicies_
List of supported EditPolicies.
Definition EditPart.hh:105

References assert, editPolicies_, figure_, and garbageCollected_.

◆ EditPart() [2/2]

EditPart::EditPart ( EditPart old)
private

Copying not allowed.

Member Function Documentation

◆ addChild()

void EditPart::addChild ( EditPart child)

Adds an EditPart as a child.

Parameters
childThe new child to be added.

Definition at line 260 of file EditPart.cc.

260 {
262 assert(figure_ != NULL);
264 children_.push_back(child);
265 }
266}
static bool containsValue(const ContainerType &aContainer, const ElementType &aKey)
std::vector< EditPart * > children_
List of children EditParts.
Definition EditPart.hh:107
Figure * figure() const
EditPart * child(unsigned int index) const
virtual void addChild(Figure *child)

References Figure::addChild(), assert, child(), children_, ContainerTools::containsValue(), figure(), and figure_.

Referenced by UnitPortFactory::addSocket(), MachineEditPartFactory::createBiDirBridge(), MachineEditPartFactory::createEditPart(), BusFactory::createEditPart(), FUFactory::createEditPart(), GCUFactory::createEditPart(), IUFactory::createEditPart(), RFFactory::createEditPart(), SegmentFactory::createEditPart(), MachineEditPartFactory::getBusChains(), MachineEditPartFactory::getSockets(), and MachineEditPartFactory::getUnits().

Here is the call graph for this function:

◆ canHandle()

bool EditPart::canHandle ( Request request) const

Tells whether this EditPart can handle a certain type of Request.

Parameters
requestThe Request to be asked if it can be handled.
Returns
true if an EditPolicy supporting the given Request is installed to this EditPart, false otherwise.

Definition at line 316 of file EditPart.cc.

316 {
317 vector<EditPolicy*>::const_iterator i = editPolicies_.begin();
318 for (; i != editPolicies_.end(); i++) {
319 if ((*i)->canHandle(request)) {
320 return true;
321 }
322 }
323 return false;
324}

References editPolicies_.

Referenced by CopyComponentCmd::isEnabled(), CutComponentCmd::isEnabled(), DeleteComponentCmd::isEnabled(), ModifyComponentCmd::isEnabled(), ConnectTool::leftClick(), ProximMachineCanvasTool::onMouseEvent(), ConnectTool::onMouseEvent(), SelectTool::onMouseEvent(), ProximMachineStateWindow::onSimulationStop(), and ConnectTool::updateStatusline().

◆ child()

EditPart * EditPart::child ( unsigned int  index) const

◆ childCount()

int EditPart::childCount ( ) const

◆ distance()

float EditPart::distance ( wxPoint  p,
wxRect  r 
)
staticprivate

Calculates distance between a point and a rectangle.

Parameters
pPosition.
rRectangle.
Returns
Distance between point and rectangle. Zero if the point is in the rectangle.

Definition at line 335 of file EditPart.cc.

335 {
336 float xr = 0;
337 float yr = 0;
338 float xp = static_cast<float>(p.x);
339 float yp = static_cast<float>(p.y);
340
341 xr = static_cast<float>(max(min(p.x, r.GetRight()), r.GetLeft()));
342 yr = static_cast<float>(max(min(p.y, r.GetBottom()), r.GetTop()));
343
344 float dist = sqrt((xr - xp) * (xr - xp) + (yr - yp) * (yr - yp));
345
346 return dist;
347}

Referenced by findInRange(), and findNearest().

◆ figure()

Figure * EditPart::figure ( ) const

◆ find() [1/2]

EditPart * EditPart::find ( const TTAMachine::MachinePart model)

Finds an EditPart which corresponds given machine component.

Parameters
modelMachine component to find.
Returns
EditPart of the machine component, or NULL if the component was not found.

Definition at line 134 of file EditPart.cc.

134 {
135
136 if (model == model_) {
137 return this;
138 }
139
140 EditPart* found = NULL;
141
142 // Check if the component is child of this edit part.
143 for (unsigned int i = 0; i < children_.size(); i++) {
144 found = children_[i]->find(model);
145 if (found != NULL) {
146 return found;
147 }
148 }
149
150 return NULL;
151}
EditPart * find(wxPoint point)
Definition EditPart.cc:102
TTAMachine::MachinePart * model() const

References children_, find(), model(), and model_.

Here is the call graph for this function:

◆ find() [2/2]

EditPart * EditPart::find ( wxPoint  point)

Finds an EditPart whose Figure is located in the given point.

Parameters
pointPoint in which to find an EditPart.
Returns
EditPart whose Figure is located in point or NULL if none found.

Definition at line 102 of file EditPart.cc.

102 {
103
104 EditPart* found = NULL;
105
106 // first check if a child is in point
107 for (unsigned int i = 0; i < children_.size(); i++) {
108 found = children_[i]->find(point);
109 if (found != NULL) {
110 return found;
111 }
112 }
113
114 // if no children were in located in the point, check self
115#if wxCHECK_VERSION(2, 8, 0)
116 if (selectable_ && figure_->virtualBounds().Contains(point)) {
117#else
118 if (selectable_ && figure_->virtualBounds().Inside(point)) {
119#endif
120 return this;
121 } else {
122 return NULL;
123 }
124}
virtual wxRect virtualBounds() const

References children_, figure_, find(), selectable_, and Figure::virtualBounds().

Referenced by find(), find(), MachineCanvas::findEditPart(), MachineCanvas::findEditPart(), and MachineCanvas::highlight().

Here is the call graph for this function:

◆ findInRange()

int EditPart::findInRange ( wxPoint  point,
float  radius,
std::vector< EditPart * > &  found 
)

Recursively looks for selectable EditParts including self that are in range around given coordinates.

Parameters
pointPosition for the search.
radiusSearch range.
foundFound EditParts are collected to this.
Returns
Number of found EditParts.

Definition at line 219 of file EditPart.cc.

220 {
221 int totalFound = 0;
222
223 for (unsigned int i = 0; i < children_.size(); i++) {
224 totalFound += children_[i]->findInRange(point, radius, found);
225 }
226
227 if (!selectable_) {
228 return totalFound;
229 }
230
231 if (distance(point, figure_->virtualBounds()) < radius) {
232 found.push_back(this);
233 return totalFound + 1;
234 }
235 return totalFound;
236}
static float distance(wxPoint p, wxRect r)
Definition EditPart.cc:335

References children_, distance(), figure_, findInRange(), selectable_, and Figure::virtualBounds().

Referenced by MachineCanvas::findEditPartsInRange(), and findInRange().

Here is the call graph for this function:

◆ findNearest()

EditPart * EditPart::findNearest ( wxPoint  point,
const EditPart exclude = NULL 
)

Finds an EditPart whose Figure is nearest to the given point or first found EditPart whose figure contains the given point.

Parameters
pointPoint in which to find the nearest EditPart.
excludeAn EditPart which is not included in the search.
Returns
EditPart if the search found one. Otherwise returns NULL.

Definition at line 162 of file EditPart.cc.

162 {
163 EditPart* found = NULL;
164 EditPart* lastFound = NULL;
165 int lastDist = std::numeric_limits<int>::max();
166
167 for (unsigned int i = 0; i < children_.size(); i++) {
168 found = children_[i]->findNearest(point, exclude);
169 if (found != NULL) {
170 wxRect foundRect = found->figure()->virtualBounds();
171
172#if wxCHECK_VERSION(2, 8, 0)
173 if (foundRect.Contains(point)) {
174#else
175 if (foundRect.Inside(point)) {
176#endif
177 assert(found->selectable());
178 return found;
179 }
180
181 if (distance(point, foundRect) < lastDist) {
182 lastFound = found;
183 lastDist = distance(point, foundRect);
184 }
185 }
186 }
187
188 if (!selectable_ || this == exclude) {
189 return lastFound;
190 }
191
192 // Check if this part's figure is closer to given point or
193 // contains the point.
194#if wxCHECK_VERSION(2, 8, 0)
195 if(figure_->virtualBounds().Contains(point)) {
196#else
197 if (figure_->virtualBounds().Inside(point)) {
198#endif
199 return this;
200 } else {
201 if (distance(point, figure_->virtualBounds()) < lastDist) {
202 return this;
203 } else {
204 return lastFound;
205 }
206 }
207}
EditPart * findNearest(wxPoint point, const EditPart *exclude=NULL)
Definition EditPart.cc:162
bool selectable() const

References assert, children_, distance(), figure(), figure_, findNearest(), selectable(), selectable_, and Figure::virtualBounds().

Referenced by findNearest().

Here is the call graph for this function:

◆ hasEditPartRecursive()

bool EditPart::hasEditPartRecursive ( const EditPart part) const

Looks for given EditPart recursively.

Parameters
partEditPart to look up.
Returns
True if tree has given EditPart.

Definition at line 274 of file EditPart.cc.

274 {
275 if (part == this) {
276 return true;
277 }
278
279 for (unsigned int i = 0; i < children_.size(); i++) {
280 if (children_.at(i)->hasEditPartRecursive(part)) {
281 return true;
282 }
283 }
284 return false;
285}

References children_.

Referenced by MachineCanvas::hasEditPart().

◆ installEditPolicy()

void EditPart::installEditPolicy ( EditPolicy editpolicy)

Installs a new EditPolicy.

Parameters
editpolicyThe EditPolicy to be installed.
Note
Only one EditPolicy per Request type should be installed. If two or more EditPolicies are able to handle one type of Request, it is not defined, which EditPolicy will be chosen.

Definition at line 247 of file EditPart.cc.

247 {
248 if (editpolicy->host() == NULL) {
249 editpolicy->setHost(this);
250 }
251 editPolicies_.push_back(editpolicy);
252}
void setHost(EditPart *host)
EditPart * host() const

References editPolicies_, EditPolicy::host(), and EditPolicy::setHost().

Referenced by MachineEditPartFactory::createBiDirBridge(), BridgeFactory::createEditPart(), BusFactory::createEditPart(), FUFactory::createEditPart(), GCUFactory::createEditPart(), IUFactory::createEditPart(), RFFactory::createEditPart(), SegmentFactory::createEditPart(), SocketFactory::createEditPart(), and UnitPortFactory::createEditPart().

Here is the call graph for this function:

◆ model()

TTAMachine::MachinePart * EditPart::model ( ) const

◆ operator=()

EditPart & EditPart::operator= ( EditPart old)
private

Assignment not allowed.

◆ parent()

EditPart * EditPart::parent ( ) const

◆ performRequest()

ComponentCommand * EditPart::performRequest ( Request request) const

If an EditPolicy supporting the given Request is installed to this EditPart, a corresponding Command will be returned or NULL if no EditPolicies supporting the Request is found.

Parameters
requestThe Request to be performed.
Returns
A command corresponding to the given Request, if an EditPolicy supporting it is installed, NULL otherwise.

Definition at line 297 of file EditPart.cc.

297 {
298 vector<EditPolicy*>::const_iterator i = editPolicies_.begin();
299 for (; i != editPolicies_.end(); i++) {
300 ComponentCommand* command = (*i)->getCommand(request);
301 if (command != NULL) {
302 return command;
303 }
304 }
305 return NULL;
306}

References editPolicies_.

Referenced by CopyComponentCmd::Do(), CutComponentCmd::Do(), DeleteComponentCmd::Do(), ModifyComponentCmd::Do(), ConnectTool::leftClick(), ProximMachineCanvasTool::onMouseEvent(), SelectTool::onMouseEvent(), ProximMachineStateWindow::onSimulationStop(), and ConnectTool::updateStatusline().

◆ putGarbage()

void EditPart::putGarbage ( std::set< EditPart * > &  trashbag)

Puts all children and this EditPart to the trashbag.

Parameters
trashbagThe trashbag.

Definition at line 87 of file EditPart.cc.

87 {
88 for (unsigned i = 0; i < children_.size(); i++) {
89 children_[i]->putGarbage(trashbag);
90 }
91 trashbag.insert(this);
92 garbageCollected_ = true;
93}

References children_, and garbageCollected_.

Referenced by RootEditPart::collectTrash().

◆ selectable()

bool EditPart::selectable ( ) const

◆ selected()

bool EditPart::selected ( ) const

◆ setFigure()

void EditPart::setFigure ( Figure figure)

◆ setModel()

void EditPart::setModel ( TTAMachine::MachinePart model)

◆ setParent()

void EditPart::setParent ( EditPart parent)

◆ setSelectable()

void EditPart::setSelectable ( bool  selectable)

◆ setSelected()

void EditPart::setSelected ( bool  select)

Member Data Documentation

◆ children_

std::vector<EditPart*> EditPart::children_
protected

List of children EditParts.

Definition at line 107 of file EditPart.hh.

Referenced by addChild(), find(), find(), findInRange(), findNearest(), hasEditPartRecursive(), and putGarbage().

◆ editPolicies_

std::vector<EditPolicy*> EditPart::editPolicies_
protected

List of supported EditPolicies.

Definition at line 105 of file EditPart.hh.

Referenced by canHandle(), installEditPolicy(), performRequest(), and ~EditPart().

◆ figure_

Figure* EditPart::figure_
protected

◆ garbageCollected_

bool EditPart::garbageCollected_
protected

Helper member to prevent improper deletion.

Definition at line 102 of file EditPart.hh.

Referenced by RootEditPart::collectTrash(), putGarbage(), RootEditPart::setContents(), and ~EditPart().

◆ model_

TTAMachine::MachinePart* EditPart::model_
protected

Machine component corresponding to this EditPart.

Definition at line 95 of file EditPart.hh.

Referenced by find().

◆ parent_

EditPart* EditPart::parent_
protected

Parent of this EditPart.

Definition at line 91 of file EditPart.hh.

◆ selectable_

bool EditPart::selectable_
protected

Tells whether the EditPart is selectable or not.

Definition at line 97 of file EditPart.hh.

Referenced by find(), findInRange(), and findNearest().

◆ selected_

bool EditPart::selected_
protected

Tells whether the EditPart is selected or not.

Definition at line 99 of file EditPart.hh.


The documentation for this class was generated from the following files: