wxArt2D
wire.h
Go to the documentation of this file.
1 /*! \file wx/canvas/wire.h
2  \brief wire classes for connecting objects.
3 
4  Classes for auto (re)routing wires (a2dWirePolylineL) are here.
5 
6  \author Michael Sögtrop
7 
8  Copyright: 2003-2004 (c) Michael Sögtrop
9 
10  Licence: wxWidgets Licence
11 
12  RCS-ID: $Id: wire.h,v 1.9 2006/12/13 21:43:24 titato Exp $
13 */
14 
15 #ifndef __WXWIRE_H__
16 #define __WXWIRE_H__
17 
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21 
22 #include "wx/artbase/afmatrix.h"
23 #include "wx/geometry.h"
24 #include "wx/artbase/bbox.h"
25 
26 #include "wx/canvas/canobj.h"
27 #include "wx/canvas/canprim.h"
28 #include "wx/canvas/polygon.h"
29 #include "wx/canvas/drawing.h"
30 
31 class A2DCANVASDLLEXP a2dWirePolylineL;
32 
33 //! a2dWirePolylineL is a polyline that adjusts itself when the objects it connects move
34 /*!
35  This is done by taking the position of the pins of the connected a2dCanvasObject's,
36  and based on that recalculate the position of the polyline points
37 
38  \ingroup canvasobject
39 
40  \sa a2dWires
41 */
42 class A2DCANVASDLLEXP a2dWirePolylineL: public a2dPolylineL
43 {
44  DECLARE_EVENT_TABLE()
45 public:
46 
48  a2dWirePolylineL( a2dVertexList* points, bool spline = false );
49  a2dWirePolylineL( const a2dWirePolylineL& poly, CloneOptions options, a2dRefMap* refs );
51 
52  void SetConnectionInfo(
53  bool inverted, //!< The wire is inverted (drawn from end to begin)
54  a2dPinClass* objBegin, //!< The required pin class in the pin of the object at the start of the wire
55  a2dPinClass* objEnd //!< The required pin class in the pin of the object at the end of the wire
56  );
57 
58  a2dPinClass* GetStartPinClass() const { return m_wireBegin; }
59  void SetStartPinClass( a2dPinClass* startPinClass ) { m_wireBegin = startPinClass; }
60 
61  a2dPinClass* GetEndPinClass() const { return m_wireEnd; }
62  void SetEndPinClass( a2dPinClass* endPinClass ) { m_wireEnd = endPinClass; }
63 
64  //! set true result in having straight lines rerouted between begin and end pin
65  void SetRouteOneLine( bool oneLine ) { m_oneLine = oneLine; }
66 
67  //! see SetRouteOneLine()
68  bool GetRouteOneLine() { return m_oneLine; }
69 
70  //! indicated if the wire still needs to be rerouted, used in routing algorithms of wire between objects.
71  void SetReroute( bool onOff ) { m_reroute = onOff; }
72 
73  //! see SetReroute()
74  bool GetReroute() const { return m_reroute; }
75 
76  //! indicated if the wire is added recently to be rerouted, used in routing algorithms of wire between objects.
77  void SetRerouteAdded( bool onOff ) { m_rerouteAdd = onOff; }
78 
79  //! see SetRerouteAdded()
80  bool GetRerouteAdded() const { return m_rerouteAdd; }
81 
82  //! used to set order of rerouting in a set of lines.
83  void SetPriority( wxUint8 priority ) { m_priority = priority; }
84 
85  //! See SetPriority()
86  wxUint8 GetPriority() const { return m_priority; }
87 
88  virtual bool IsConnect() const;
89  virtual bool NeedsUpdateWhenConnected() const;
90 
91  //! adjust pin angles to the last segment at end and begin of wire.
92  void AdjustBeginEndPinAngle();
93 
94  //! a tool designed for editing a a2dPolylineL, can in principle be used for
95  //! a a2dWirePolylineL, if it makes sure that the pins on it, are synchronized with the segments
96  //! which change because of the editing. Therefore in a2dPolylineL, at the right points
97  //! AdjustAfterChange is called to achieve this.
98  virtual bool AdjustAfterChange( bool final );
99 
100  //! Split wire at pin given, and add the new split off wire part to parent, creates a new pin at split.
101  /*!
102  Used also in a2dCommand_SplitAtPin.
103  The split of part of this wire, is a cloned version of itself, the same for the split pin.
104 
105  \param parent The parent object of this wiure, and new created wire.
106  \param splitPin The pin were the split will take place, id not part of the wire yet, it will be added.
107  \param splitPinClone The new pin were the split was made, being part of the new wire part
108  \param clone New wire part after the split pin.
109  */
110  a2dPin* SplitAtPin( a2dCanvasObject* parent, a2dPin* splitPin, a2dPin* splitPinClone = NULL, a2dWirePolylineL* clone = NULL, double hitMargin = a2dACCUR );
111 
112  //! Join two pins making one pin, and merge the this wire with the parent wire of the other pin
113  /*!
114  \param parent The parent of this wire, from which connected wire will be removed.
115  \param joinPin The pin to join to.
116  \param joinPinOther The connected pin to join and remove
117  */
118  bool JoinAtPin( a2dCanvasObject* parent, a2dPin* joinPin, a2dPin* joinPinOther );
119 
120  //! join two wires at joinPin and joinPinOther will be removed.
121  /*!
122  \param parent The parent of this wire, from which connected wire will be removed.
123  \param joinPin The pin to join/remove
124  \param joinPinOther The connected pin to join/remove
125  \param inFront set true if other wire it's segments wre added in front of the segments of this line.
126  \param secondRedirect set true if second wire needed to be reversed in direction
127  */
128  bool MergAtPin( a2dCanvasObject* parent, a2dPin* joinPin, a2dPin* joinPinOther, bool& inFront, bool& secondRedirect );
129 
130  //! make the direction of vertexes the oposite
131  void Reverse();
132 
133 #if wxART2D_USE_CVGIO
134  virtual void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
135  virtual void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
136 #endif //wxART2D_USE_CVGIO
137 
138  //! Set position of an end point and possibly one adjacent point
139  void SetEndPoint( int iEnd, int iNext, double x, double y, bool final );
140 
141  //! Check if the begin or end pin of the wire is dislocated
142  bool IsDislocated();
143 
144 
145  //! generates pins on all possible locations where the wire can be connected.
146  /*!
147  Depending on m_wireBegin and m_wireEnd combined with parameter task, a certain type of a2dPin will be created.
148 
149  \param pinClass if not NULL, only generate temporary pins that may connect to this pinClass.
150  \param task what/how to connect
151  \param x can be used to create pins depending on the poition of the mouse inside the object.
152  \param y can be used to create pins depending on the poition of the mouse inside the object.
153  */
154  virtual bool GeneratePinsPossibleConnections( a2dPinClass* pinClass, a2dConnectTask task, double x, double y, double margin = 0 );
155 
156  //! if wire has unconnected pins, they will be removed, or zero lenght it will be released.
157  //! use commands for undo.
158  void OptimizeRerouteWires( a2dCanvasObject* parent, bool removeZero = true, bool allowredirect = true );
159 
160  DECLARE_DYNAMIC_CLASS( a2dWirePolylineL )
161 
162 protected:
163 
164  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
165  void OnChar( wxKeyEvent& event );
166 
167  virtual bool DoStartEdit( wxUint16 editmode, wxEditStyle editstyle );
168 
169  virtual bool GeneratePins( a2dPinClass* toConnectTo, a2dConnectTask task, double x, double y, double margin = 0 );
170 
171  a2dPinClass* m_objBegin; //!< The pin class in the pin of the object at the start of the wire
172  a2dPinClass* m_objEnd; //!< The pin class in the pin of the object at the end of the wire
173 
174  a2dPinClass* m_wireBegin; //!< The pin class in the pin of the wire at the start of the wire
175  a2dPinClass* m_wireEnd; //!< The pin class in the pin of the wire at the end of the wire
176 
177  //! This is used temporarily during editing and need not be saved
178  bool m_wasVertical: 1;
179 
180  bool m_inverted: 1; //!< The wire is inverted (drawn from end to begin)
181 
182  bool m_oneLine: 1;
183 
184  bool m_reroute: 1;
185 
186  bool m_rerouteAdd: 1;
187 
188  wxUint8 m_priority: 8;
189 
190 private:
191  //!this is a not implemented copy constructor that avoids automatic creation of one
192  a2dWirePolylineL( const a2dWirePolylineL& other );
193 };
194 
195 //! Temporary object used in editing connected objects.
196 /*! when editing connected objects, the wires connections are cloned and
197  shown as edit copies while editing. The objects on the other end of those wires
198  copies are terminated with this object.
199  This makes it possible to find the original object on that end of the wire if needed.
200  Next to that rendering is as a connected pin, while editing.
201 */
202 class A2DCANVASDLLEXP a2dWireEnd: public a2dCanvasObject
203 {
204  DECLARE_DYNAMIC_CLASS( a2dWireEnd )
205 
206 public:
207 
208  a2dWireEnd( double x = 0 , double y = 0 );
209  a2dWireEnd( const a2dWireEnd& obj, CloneOptions options, a2dRefMap* refs );
210 
211 protected:
212 
213  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
214 
215 private:
216 
217  //!this is a not implemented copy constructor that avoids automatic creation of one
218  a2dWireEnd( const a2dWireEnd& other );
219 };
220 
221 
222 class A2DCANVASDLLEXP a2dCommand_SplitAtPin: public a2dCommand
223 {
224 public:
225  //!
226  /*! \ingroup commandid
227  */
228  static const a2dCommandId Id;
229 
231 
232  a2dCommand_SplitAtPin( a2dCanvasObject* parent, a2dPin* splitPin, double hitMargin );
233 
234  ~a2dCommand_SplitAtPin( void );
235 
236  bool Do();
237  bool Undo();
238  bool Redo();
239 
240  inline a2dCanvasCommandProcessor* GetCanvasCmp() { return wxStaticCast( m_cmp, a2dCanvasCommandProcessor ); }
241 
242  a2dCanvasObjectPtr m_parent;
243  a2dPinPtr m_splitPin;
244  a2dPinPtr m_splitPinClone;
247  double m_hitMargin;
248 };
249 
250 class A2DCANVASDLLEXP a2dCommand_JoinAtPin: public a2dCommand
251 {
252 public:
253  //!
254  /*! \ingroup commandid
255  */
256  static const a2dCommandId Id;
257 
259 
260  a2dCommand_JoinAtPin( a2dCanvasObject* parent, a2dPin* joinPin, a2dPin* joinPin2 );
261 
262  ~a2dCommand_JoinAtPin( void );
263 
264  bool Do();
265  bool Undo();
266  bool Redo();
267 
268  inline a2dCanvasCommandProcessor* GetCanvasCmp() { return wxStaticCast( m_cmp, a2dCanvasCommandProcessor ); }
269 
270  a2dCanvasObjectPtr m_parent;
271  a2dPinPtr m_joinPin;
272  a2dPinPtr m_joinPin2;
273  a2dPinPtr m_renamedPin;
275  a2dSmrtPtr<a2dWirePolylineL> m_wirePin2;
277  bool m_secondRedirect;
278  bool m_inFront;
279 };
280 
281 class A2DCANVASDLLEXP a2dCommand_EliminateMatrix: public a2dCommand
282 {
283 public:
284 
285  //! \ingroup commandid
286  static const a2dCommandId Id;
287 
289 
291 
293 
294  bool Do();
295  bool Undo();
296  bool Redo();
297 
298  inline a2dCanvasCommandProcessor* GetCanvasCmp() { return wxStaticCast( m_cmp, a2dCanvasCommandProcessor ); }
299 
300  a2dAffineMatrix m_matrix;
302 };
303 
304 class A2DCANVASDLLEXP a2dCommand_RemoveZeroWire: public a2dCommand
305 {
306 public:
307 
308  //! \ingroup commandid
309  static const a2dCommandId Id;
310 
312 
314 
315  ~a2dCommand_RemoveZeroWire( void );
316 
317  bool Do();
318  bool Undo();
319  bool Redo();
320 
321  inline a2dCanvasCommandProcessor* GetCanvasCmp() { return wxStaticCast( m_cmp, a2dCanvasCommandProcessor ); }
322 
323  a2dCanvasObjectPtr m_parent;
324  a2dPinPtr m_joinPin;
325  a2dPinPtr m_joinPin2;
327 };
328 
329 /*!
330  A virtual wire is used to make connection between object without really drawing a wire.
331  The object makes conenctions based on a label name.
332 */
333 class a2dVirtWire : public a2dText
334 {
335  wxDECLARE_DYNAMIC_CLASS(a2dVirtWire);
336 public:
337  a2dVirtWire( a2dCanvasObject* m_parent = NULL, const wxString& VirtWireName = wxEmptyString, a2dPinClass* pinclass = a2dPinClass::Standard );
338  a2dVirtWire( const a2dVirtWire &src, CloneOptions options, a2dRefMap* refs );
339 
340  virtual bool IsVirtConnect() const { return true; }
341 
342  void SetParent( a2dCanvasObject* parent ) { m_parent = parent; }
343  a2dCanvasObject* GetParent() const { return m_parent; }
344 
345  void SetVirtWireName( const wxString& VirtWireName ) { m_VirtWireName = VirtWireName; }
346  const wxString GetVirtWireName() const { return m_VirtWireName; }
347 
348  virtual bool FindConnectedPins( a2dCanvasObjectList& result, a2dPin* pin = NULL, bool walkWires = true, a2dPinClass* searchPinClass = NULL, a2dCanvasObject* isConnectedTo = NULL );
349 
350 protected:
351  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
352  virtual bool DoStartEdit( wxUint16 editmode, wxEditStyle editstyle );
353 
354  virtual void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
355  virtual void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
356 
357  virtual void DoRender( a2dIterC& ic, OVERLAP clipparent );
358 
359 private:
360  a2dVirtWire(const a2dVirtWire &src);
361 
362  wxString m_VirtWireName;
363  a2dCanvasObject* m_parent; // needed to get to other a2dVirtWire objects, which form the virtual connection
364 };
365 
366 /*!
367  * a2dVirtWireDlg class declaration
368  */
369 
370 class a2dVirtWireDlg: public wxDialog
371 {
372 
373 public:
374 
375  wxDECLARE_EVENT_TABLE();
376 
377 public:
378 
379  a2dVirtWireDlg(wxWindow *parent, a2dVirtWire* virtWire );
380  virtual ~a2dVirtWireDlg() {}
381 
382  void CreateControls();
383 
384  a2dVirtWire* GetVirtWire() const { return m_virtWire; }
385 
386 protected:
387  wxBoxSizer *bs;
388  wxBoxSizer *bsN;
389  wxComboBox *m_CBName;
390 
391  a2dVirtWire* m_virtWire;
392 };
393 
394 
396 {
397 
398 public:
399 
400  a2dSingleRoute( double offset, double smax );
401  ~a2dSingleRoute(){}
402 
403  //! first & last segment min size
404  double m_offset;
405  //! object min half size
406  double m_smax;
407 
408  double m_p[8][2];
409  int m_pnr;
410 
411  /*!
412  Computes & corrects the connection path from an object Out pad to an object In
413  pad.
414 
415  Entry:
416  outPad - the Out pad to be connected
417  inPad - the In pad to be connected
418  Exit:
419  nump - the number of connection points
420  pts - the connection point list
421  */
422  void ComputeCon( a2dPin* outPad, a2dPin* inPad );
423 
424  /*!
425  Computes & corrects the connection path from an object Out pad to a vertex at a certain angle
426 
427  Entry:
428  outPad - the Out pad to be connected
429  xw - x vertex to route to
430  yw - y vertex to route to
431  angle - angle of arrivel
432 
433  Exit:
434  nump - the number of connection points
435  pts - the connection point list
436  */
437  void ComputeConToWireVertex( a2dPin* outPad, double xw, double yw, double angle );
438 
439 protected:
440 
441  /*!
442  Computes the connection path from an object Out pad to an object In pad using
443  the orthogonal path algorithm.
444 
445  Entry:
446  xo - Out pad x coordinate
447  yo - Out pad y coordinate
448  diro - Out pad direction
449  xi - In pad x coordinate
450  yi - In pad y coordinate
451  diri - In pad direction
452  Exit:
453  p - the connection point list
454  Return:
455  the number of connection points
456  */
457  void Connect ( double xo, double yo, int diro, double xi, double yi, int diri );
458  void Correct ( double x, double y, double w, double h );
459  void Transform ( int mode, int dout, double xout, double yout, double x, double y, double* tx, double* ty );
460  void Shape3P ( double xi, double yi );
461  void Shape4PD ( double xi, double yi );
462  void Shape4PU ( double xi, double yi );
463  void Shape5PB ( double xi, double yi, int sign );
464  void Shape5PT ( double xi, double yi, int sign );
465  void Shape6P ( double xi, double yi, int sign );
466  int Overcross ( double x, double y, double w, double h, double x1, double y1, double x2, double y2 );
467  void Optimize ();
468 };
469 
470 #endif
virtual bool IsVirtConnect() const
object is a virtual connection (connects invisible with other objects without using wires ) ...
Definition: wire.h:340
Temporary object used in editing connected objects.
Definition: wire.h:202
all basic primitives derived from a2dCanvasObject
a2dConnectTask
flags for searching a connecting a2dpinClass, for the connecting task at hand.
Definition: connectgen.h:40
#define a2dACCUR
accuracy used to have some limit to calculation like hittesting
Definition: artglob.h:41
class to map references to objects stored in XML, in order to make the connection later on...
Definition: gen.h:3462
a2dPin is used in a2dCanvasObject to add pins to it.
Definition: canpin.h:233
This is a class/type description for a2dPin&#39;s.
Definition: canpin.h:628
Ref Counted base object.
Definition: gen.h:1045
void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
write object specific CVGL data
Definition: polygon.cpp:2570
virtual bool GeneratePinsPossibleConnections(a2dPinClass *pinClass, a2dConnectTask task, double x, double y, double margin=0)
generates pins on all possible locations where the object can be connected.
Definition: canobj.cpp:3156
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:819
a command processor specially designed to work with a a2dCanvasDocument
Definition: drawing.h:1046
OVERLAP
Result of a a2dBoundingBox intersection or hittest.
Definition: bbox.h:24
The base class for all drawable objects in a a2dCanvasDocument.
void SetReroute(bool onOff)
indicated if the wire still needs to be rerouted, used in routing algorithms of wire between objects...
Definition: wire.h:71
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
void SetRouteOneLine(bool oneLine)
set true result in having straight lines rerouted between begin and end pin
Definition: wire.h:65
vertex list of line and arc segments.
Definition: polyver.h:600
double m_smax
object min half size
Definition: wire.h:406
a2dWirePolylineL is a polyline that adjusts itself when the objects it connects move ...
Definition: wire.h:42
a2dText is an abstract base class.
Definition: cantext.h:93
void SetPriority(wxUint8 priority)
used to set order of rerouting in a set of lines.
Definition: wire.h:83
polyline defined with list of points.
Definition: polygon.h:332
bounding class for optimizing drawing speed.
#define wxStaticCast(obj, className)
The wxWindows 2.4.2 wxStaticCast is buggy. It evaluates its argument twice.
Definition: gen.h:123
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:862
double m_offset
first &amp; last segment min size
Definition: wire.h:404
Contains a2dDrawing Class to hold a drawing.
bool GetRerouteAdded() const
see SetRerouteAdded()
Definition: wire.h:80
void SetParent(a2dCanvasObject *parent)
set parent object of the pin or some other objects that needs a parent
Definition: wire.h:342
Each a2dCommand is given a command id at construction.
Definition: comevt.h:99
A 2x3 affine matrix class for 2D transformations.
Definition: afmatrix.h:53
void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
load object specific CVG data
Definition: polygon.cpp:2607
while iterating a a2dCanvasDocument, this holds the context.
Definition: canobj.h:3212
virtual bool AdjustAfterChange(bool final)
adjust the polygon after a point change
Definition: polygon.cpp:835
static a2dPinClass * Standard
Pins of this class can only connect to pins of the same class.
Definition: canpin.h:766
bool GetRouteOneLine()
see SetRouteOneLine()
Definition: wire.h:68
a2dCanvasObject * GetParent() const
Definition: wire.h:343
void SetRerouteAdded(bool onOff)
indicated if the wire is added recently to be rerouted, used in routing algorithms of wire between ob...
Definition: wire.h:77
all polygon and polyline a2dCanvasObject are here.
affine matrix class
virtual bool NeedsUpdateWhenConnected() const
used in case of flexible canvas objects (wires).
Definition: canobj.h:1841
wxUint8 GetPriority() const
See SetPriority()
Definition: wire.h:86
virtual bool IsConnect() const
return true, if this object is used to connect other object&#39;s using rubberband like structures...
Definition: canobj.h:1831
list of a2dObject&#39;s
Definition: gen.h:3157
CloneOptions
options for cloning
Definition: gen.h:1200
bool GetReroute() const
see SetReroute()
Definition: wire.h:74
virtual a2dObject * DoClone(CloneOptions options, a2dRefMap *refs) const
Clone this object and return a pointer to the new object.
Definition: polygon.cpp:1848
wxEditStyle
Definition: canobj.h:109
a base command for the a2dCommandProcessor
Definition: comevt.h:140
wire.h Source File -- Sun Oct 12 2014 17:04:26 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation