1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVX_SVDOEDGE_HXX
21 #define INCLUDED_SVX_SVDOEDGE_HXX
24 #include <svx/svdotext.hxx>
25 #include <svx/svdglue.hxx>
26 #include <svx/svxdllapi.h>
32 namespace sdr
{ namespace properties
{
33 class ConnectorProperties
;
37 /// Utility class SdrObjConnection
38 class SdrObjConnection
40 friend class SdrEdgeObj
;
41 friend class ImpEdgeHdl
;
42 friend class SdrCreateView
;
45 Point aObjOfs
; // set during dragging of a node
46 SdrObject
* pObj
; // referenced object
47 sal_uInt16 nConId
; // connector number
49 bool bBestConn
: 1; // true -> the best-matching connector is searched for
50 bool bBestVertex
: 1; // true -> the best-matching vertex to connect is searched for
51 bool bAutoVertex
: 1; // autoConnector at apex nCon
52 bool bAutoCorner
: 1; // autoConnector at corner nCon
55 SdrObjConnection() { ResetVars(); }
56 SVX_DLLPUBLIC
~SdrObjConnection();
59 bool TakeGluePoint(SdrGluePoint
& rGP
) const;
61 void SetBestConnection( bool rB
) { bBestConn
= rB
; };
62 void SetBestVertex( bool rB
) { bBestVertex
= rB
; };
63 void SetAutoVertex( bool rB
) { bAutoVertex
= rB
; };
64 void SetConnectorId( sal_uInt16 nId
) { nConId
= nId
; };
66 bool IsBestConnection() const { return bBestConn
; };
67 bool IsAutoVertex() const { return bAutoVertex
; };
68 sal_uInt16
GetConnectorId() const { return nConId
; };
69 SdrObject
* GetObject() const { return pObj
; }
73 enum class SdrEdgeLineCode
{ Obj1Line2
, Obj1Line3
, Obj2Line2
, Obj2Line3
, MiddleLine
};
75 /// Utility class SdrEdgeInfoRec
79 // The 5 distances are set on dragging or via SetAttr and are
80 // evaluated by ImpCalcEdgeTrack. Only 0-3 longs are transported
81 // via Get/SetAttr/Get/SetStyleSh though.
88 // Following values are set by ImpCalcEdgeTrack
89 long nAngle1
; // exit angle at Obj1
90 long nAngle2
; // exit angle at Obj2
91 sal_uInt16 nObj1Lines
; // 1..3
92 sal_uInt16 nObj2Lines
; // 1..3
93 sal_uInt16 nMiddleLine
; // 0xFFFF=none, otherwiese point number of the beginning of the line
94 char cOrthoForm
; // form of the right-angled connector, e.g., 'Z','U',I','L','S',...
106 Point
& ImpGetLineVersatzPoint(SdrEdgeLineCode eLineCode
);
107 sal_uInt16
ImpGetPolyIdx(SdrEdgeLineCode eLineCode
, const XPolygon
& rXP
) const;
108 bool ImpIsHorzLine(SdrEdgeLineCode eLineCode
, const XPolygon
& rXP
) const;
109 void ImpSetLineVersatz(SdrEdgeLineCode eLineCode
, const XPolygon
& rXP
, long nVal
);
110 long ImpGetLineVersatz(SdrEdgeLineCode eLineCode
, const XPolygon
& rXP
) const;
114 /// Utility class SdrEdgeObjGeoData
115 class SdrEdgeObjGeoData
: public SdrTextObjGeoData
118 SdrObjConnection aCon1
; // connection status of the beginning of the line
119 SdrObjConnection aCon2
; // connection status of the end of the line
120 std::unique_ptr
<XPolygon
> pEdgeTrack
;
121 bool bEdgeTrackDirty
; // true -> connector track needs to be recalculated
122 bool bEdgeTrackUserDefined
;
123 SdrEdgeInfoRec aEdgeInfo
;
127 virtual ~SdrEdgeObjGeoData() override
;
131 /// Utility class SdrEdgeObj
132 class SVX_DLLPUBLIC SdrEdgeObj
: public SdrTextObj
135 // to allow sdr::properties::ConnectorProperties access to ImpSetAttrToEdgeInfo()
136 friend class sdr::properties::ConnectorProperties
;
138 friend class SdrCreateView
;
139 friend class ImpEdgeHdl
;
142 virtual sdr::contact::ViewContact
* CreateObjectSpecificViewContact() override
;
143 virtual sdr::properties::BaseProperties
* CreateObjectSpecificProperties() override
;
145 SdrObjConnection aCon1
; // Connection status of the beginning of the line
146 SdrObjConnection aCon2
; // Connection status of the end of the line
148 XPolygon
* pEdgeTrack
;
149 sal_uInt16 nNotifyingCount
; // Locking
150 SdrEdgeInfoRec aEdgeInfo
;
152 bool bEdgeTrackDirty
: 1; // true -> Connection track needs to be recalculated
153 bool bEdgeTrackUserDefined
: 1;
155 // Bool to allow suppression of default connects at object
156 // inside test (HitTest) and object center test (see ImpFindConnector())
157 bool mbSuppressDefaultConnect
: 1;
159 // Flag value for avoiding infinite loops when calculating
160 // BoundRects from ring-connected connectors. A coloring algorithm
161 // is used here. When the GetCurrentBoundRect() calculation of a
162 // SdrEdgeObj is running, the flag is set, else it is always
164 bool mbBoundRectCalculationRunning
: 1;
166 // #i123048# need to remember if layouting was suppressed before to get
167 // to a correct state for first real layouting
168 bool mbSuppressed
: 1;
171 // Interface to default connect suppression
172 void SetSuppressDefaultConnect(bool bNew
) { mbSuppressDefaultConnect
= bNew
; }
173 bool GetSuppressDefaultConnect() const { return mbSuppressDefaultConnect
; }
176 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
178 static XPolygon
ImpCalcObjToCenter(const Point
& rStPt
, long nEscAngle
, const tools::Rectangle
& rRect
, const Point
& rCenter
);
179 void ImpRecalcEdgeTrack(); // recalculation of the connection track
180 XPolygon
ImpCalcEdgeTrack(const XPolygon
& rTrack0
, SdrObjConnection
& rCon1
, SdrObjConnection
& rCon2
, SdrEdgeInfoRec
* pInfo
) const;
181 XPolygon
ImpCalcEdgeTrack(const Point
& rPt1
, long nAngle1
, const tools::Rectangle
& rBoundRect1
, const tools::Rectangle
& rBewareRect1
,
182 const Point
& rPt2
, long nAngle2
, const tools::Rectangle
& rBoundRect2
, const tools::Rectangle
& rBewareRect2
,
183 sal_uIntPtr
* pnQuality
, SdrEdgeInfoRec
* pInfo
) const;
184 static bool ImpFindConnector(const Point
& rPt
, const SdrPageView
& rPV
, SdrObjConnection
& rCon
, const SdrEdgeObj
* pThis
, OutputDevice
* pOut
=nullptr);
185 static SdrEscapeDirection
ImpCalcEscAngle(SdrObject
* pObj
, const Point
& aPt2
);
186 void ImpSetTailPoint(bool bTail1
, const Point
& rPt
);
187 void ImpUndirtyEdgeTrack(); // potential recalculation of the connection track
188 void ImpDirtyEdgeTrack(); // invalidate connector path, so it will be recalculated next time
189 void ImpSetAttrToEdgeInfo(); // copying values from the pool to aEdgeInfo
190 void ImpSetEdgeInfoToAttr(); // copying values from the aEdgeInfo to the pool
195 virtual ~SdrEdgeObj() override
;
197 SdrObjConnection
& GetConnection(bool bTail1
) { return *(bTail1
? &aCon1
: &aCon2
); }
198 virtual void TakeObjInfo(SdrObjTransformInfoRec
& rInfo
) const override
;
199 virtual sal_uInt16
GetObjIdentifier() const override
;
200 virtual const tools::Rectangle
& GetCurrentBoundRect() const override
;
201 virtual const tools::Rectangle
& GetSnapRect() const override
;
202 virtual bool IsNode() const override
;
203 virtual SdrGluePoint
GetVertexGluePoint(sal_uInt16 nNum
) const override
;
204 virtual SdrGluePoint
GetCornerGluePoint(sal_uInt16 nNum
) const override
;
205 virtual const SdrGluePointList
* GetGluePointList() const override
;
206 virtual SdrGluePointList
* ForceGluePointList() override
;
208 // * for all of the below: bTail1=true: beginning of the line,
209 // otherwise end of the line
210 // * pObj=NULL: disconnect connector
211 void SetEdgeTrackDirty() { bEdgeTrackDirty
=true; }
212 void ConnectToNode(bool bTail1
, SdrObject
* pObj
) override
;
213 void DisconnectFromNode(bool bTail1
) override
;
214 SdrObject
* GetConnectedNode(bool bTail1
) const override
;
215 const SdrObjConnection
& GetConnection(bool bTail1
) const { return *(bTail1
? &aCon1
: &aCon2
); }
216 bool CheckNodeConnection(bool bTail1
) const;
218 virtual void RecalcSnapRect() override
;
219 virtual void TakeUnrotatedSnapRect(tools::Rectangle
& rRect
) const override
;
220 virtual SdrEdgeObj
* Clone() const override
;
221 SdrEdgeObj
& operator=(const SdrEdgeObj
& rObj
);
222 virtual OUString
TakeObjNameSingul() const override
;
223 virtual OUString
TakeObjNamePlural() const override
;
225 void SetEdgeTrackPath( const basegfx::B2DPolyPolygon
& rPoly
);
226 basegfx::B2DPolyPolygon
GetEdgeTrackPath() const;
228 virtual basegfx::B2DPolyPolygon
TakeXorPoly() const override
;
229 virtual sal_uInt32
GetHdlCount() const override
;
230 virtual SdrHdl
* GetHdl(sal_uInt32 nHdlNum
) const override
;
232 // special drag methods
233 virtual bool hasSpecialDrag() const override
;
234 virtual bool beginSpecialDrag(SdrDragStat
& rDrag
) const override
;
235 virtual bool applySpecialDrag(SdrDragStat
& rDrag
) override
;
236 virtual OUString
getSpecialDragComment(const SdrDragStat
& rDrag
) const override
;
239 virtual SdrObject
* getFullDragClone() const override
;
241 virtual void NbcSetSnapRect(const tools::Rectangle
& rRect
) override
;
242 virtual void NbcMove(const Size
& aSize
) override
;
243 virtual void NbcResize(const Point
& rRefPnt
, const Fraction
& aXFact
, const Fraction
& aYFact
) override
;
245 // #i54102# added rotate, mirror and shear support
246 virtual void NbcRotate(const Point
& rRef
, long nAngle
, double sn
, double cs
) override
;
247 virtual void NbcMirror(const Point
& rRef1
, const Point
& rRef2
) override
;
248 virtual void NbcShear(const Point
& rRef
, long nAngle
, double tn
, bool bVShear
) override
;
250 // #102344# Added missing implementation
251 virtual void NbcSetAnchorPos(const Point
& rPnt
) override
;
253 virtual bool BegCreate(SdrDragStat
& rStat
) override
;
254 virtual bool MovCreate(SdrDragStat
& rStat
) override
;
255 virtual bool EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
) override
;
256 virtual bool BckCreate(SdrDragStat
& rStat
) override
;
257 virtual void BrkCreate(SdrDragStat
& rStat
) override
;
258 virtual basegfx::B2DPolyPolygon
TakeCreatePoly(const SdrDragStat
& rDrag
) const override
;
259 virtual Pointer
GetCreatePointer() const override
;
260 virtual SdrObject
* DoConvertToPolyObj(bool bBezier
, bool bAddText
) const override
;
262 virtual sal_uInt32
GetSnapPointCount() const override
;
263 virtual Point
GetSnapPoint(sal_uInt32 i
) const override
;
264 virtual bool IsPolyObj() const override
;
265 virtual sal_uInt32
GetPointCount() const override
;
266 virtual Point
GetPoint(sal_uInt32 i
) const override
;
267 virtual void NbcSetPoint(const Point
& rPnt
, sal_uInt32 i
) override
;
269 virtual SdrObjGeoData
* NewGeoData() const override
;
270 virtual void SaveGeoData(SdrObjGeoData
& rGeo
) const override
;
271 virtual void RestGeoData(const SdrObjGeoData
& rGeo
) override
;
273 /** updates edges that are connected to the edges of this object
274 as if the connected objects send a repaint broadcast
279 // helper methods for the StarOffice api
280 Point
GetTailPoint( bool bTail
) const;
281 void SetTailPoint( bool bTail
, const Point
& rPt
);
282 void setGluePointIndex( bool bTail
, sal_Int32 nId
= -1 );
283 sal_Int32
getGluePointIndex( bool bTail
);
285 virtual bool TRGetBaseGeometry(basegfx::B2DHomMatrix
& rMatrix
, basegfx::B2DPolyPolygon
& rPolyPolygon
) const override
;
286 virtual void TRSetBaseGeometry(const basegfx::B2DHomMatrix
& rMatrix
, const basegfx::B2DPolyPolygon
& rPolyPolygon
) override
;
288 // for geometry access
289 ::basegfx::B2DPolygon
getEdgeTrack() const;
291 // helper method for SdrDragMethod::AddConnectorOverlays. Adds a overlay polygon for
292 // this connector to rResult.
293 basegfx::B2DPolygon
ImplAddConnectorOverlay(SdrDragMethod
& rDragMethod
, bool bTail1
, bool bTail2
, bool bDetail
) const;
296 // The following item parameters of the SdrItemPool are used to
297 // determine the actual connector line routing:
299 // sal_uInt16 EdgeFlowAngle default 9000 (= 90.00 deg), min 0, max 9000
301 // The angle at which the connecting line may run.
303 // sal_uInt16 EdgeEscAngle default 9000 (= 90.00 Deg), min 0, max 9000
304 // Object exit angle.
305 // The angle at which the connection line may exit from the object.
307 // bool EdgeEscAsRay default false
308 // true -> the connecting line emerges from the object radially.
309 // Thus, angle specification by the line ObjCenter / connector.
311 // bool EdgeEscUseObjAngle default false
312 // Object rotation angle is considered
313 // true -> when determining the connector exit angle, angle for
314 // object rotation is taken as an offset.
316 // sal_uIntPtr EdgeFlowDefDist default 0, min 0, max ?
317 // This is the default minimum distance on calculation of the
318 // connection Line to the docked objects is in logical units.
319 // This distance is overridden within the object, as soon as the
320 // user drags on the lines. When docking onto a new object,
321 // however, this default is used again.
324 // General Information About Connectors:
326 // There are nodes and edge objects. Two nodes can be joined by an
327 // edge. If a connector is connected to a node only at one end, the
328 // other end is fixed to an absolute position in the document. It is
329 // of course also possible for a connector to be "free" at both ends,
330 // i.e. not connected to a node object on each side.
332 // A connector object can also theoretically be a node object at the
333 // same time. In the first version, however, this will not yet be
336 // A connection between node and connector edge can be established by:
337 // - Interactive creation of a new edge object at the SdrView where
338 // the beginning or end point of the edge is placed on a connector
339 // (glueing point) of an already existing node object.
340 // - Interactive dragging of the beginning or end point of an
341 // existing connector edge object on the SdrView to a connector
342 // (glueing point) of an already existing node object.
344 // Moving node objects does not make any connections. Also not the
345 // direct shifting of edge endpoints on the SdrModel... Connections
346 // can also be established, if the connectors are not configured to
347 // be visible in the view.
349 // An existing connection between node and edge is retained for:
350 // - Dragging (Move/Resize/Rotate/...) of the node object
351 // - Moving a connector position in the node object
352 // - Simultaneous dragging (Move/Resize/Rotate/...) of the node and the
355 // A connection between node and edge can be removed by:
356 // - Deleting one of the objects
357 // - Dragging the edge object without simultaneously dragging the node
358 // - Deleting the connector at the node object
359 // - Undo/Redo/Repeat
360 // When dragging, the request to remove the connection must be
361 // requested from outside of the model (for example, from the
362 // SdrView). SdrEdgeObj::Move() itself does not remove the
365 // Each node object can have connectors, so-called glue points. These
366 // are the geometric points at which the connecting edge object ends
367 // when the connection is established. By default, each object has no
368 // connectors. Nevertheless, one can dock an edge in certain view
369 // settings since then, e.g., connectors can be automatically
370 // generated at the 4 vertices of the node object when needed. Each
371 // object provides 2x4 so-called default connector positions, 4 at
372 // the vertices and 4 at the corner positions. In the normal case,
373 // these are located at the 8 handle positions; exceptions here are
374 // ellipses, parallelograms, ... . In addition, user-specific
375 // connectors can be set for each node object.
377 // Then there is also the possibility to dock an edge on an object
378 // with the attribute "bUseBestConnector". The best-matching
379 // connector position for the routing of the connection line is then
380 // used from the offering of connectors of the object or/and of the
381 // vertices. The user assigns this attribute by docking the node in
382 // its center (see, e.g., Visio).
383 // 09-06-1996: bUseBestConnector uses vertex glue points only.
385 // And here is some terminology:
386 // Connector : The connector object (edge object)
387 // Node : Any object to which a connector can be glued to, e.g., a rectangle,
389 // Glue point: The point at which the connector is glued to the node object.
391 // Vertex glue points: Each node object presents these glue
392 // points inherently. Perhaps there is already the option
393 // "automatically glue to object vertex" in Draw (default is
395 // Corner glue points: These glue points, too, are already
396 // auto-enabled on objects. Similar to the ones above,
397 // there may already be an option for them in Draw (default is
399 // In contrast to Visio, vertex glue points and corner glue
400 // points are not displayed in the UI; they are simply there (if
401 // the option is activated).
402 // Custom glue points: Any number of them are present on each
403 // node object. They can be made visible using the option
404 // (always visible when editing). At the moment, however, they
405 // are not yet fully implemented.
406 // Automatic glue point selection: If the connector is docked
407 // to the node object so that the black frame encompasses the
408 // entire object, then the connector tries to find the most
409 // convenient of the 4 vertex glue points (and only of those).
411 #endif // INCLUDED_SVX_SVDOEDGE_HXX
413 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */