karbon

vselectnodes.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002, The Karbon Developers
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20
21#include "vpath.h"
22#include "vsegment.h"
23#include "vselectnodes.h"
24#include "vlayer.h"
25#include "vdocument.h"
26
27void
28VSelectNodes::visitVSubpath( VSubpath& path )
29{
30 path.first();
31
32 VSegment *curr = path.current();
33
34 while( curr )
35 {
36 if( m_rect.isEmpty() )
37 {
38 for( int i = 0; i < curr->degree(); i++ )
39 curr->selectPoint( i, m_select );
40
41 setSuccess();
42 }
43 else
44 {
45 if( m_exclusive )
46 {
47 // we are in exclusive mode, so deselect all nodes first
48 for( int i = 0; i < curr->degree(); i++ )
49 curr->selectPoint( i, false );
50 }
51
52 if( curr->isCurve() )
53 {
54 // select all control points inside the selection rect
55 for( int i = 0; i < curr->degree()-1; ++i )
56 {
57 if( m_rect.contains( curr->point( i ) ) )
58 {
59 curr->selectPoint( i, m_select );
60 setSuccess();
61 }
62 }
63 VSegment* prev = curr->prev();
64 // make sure the last control point of the previous segment and the first control point
65 // of the current segment are selected if:
66 // - both segments are curves with a smooth transition and
67 // - the previous segment's knot is selected or
68 // - one of the above mentioned control points is already selected
69 if( prev )
70 {
71 if( curr->pointIsSelected( 0 ) == m_select )
72 {
73 if( prev->isCurve() && prev->isSmooth() )
74 prev->selectPoint( prev->degree()-2, m_select );
75 }
76 else
77 {
78 if( prev->knotIsSelected() || ( prev->isCurve() && prev->isSmooth() && prev->pointIsSelected( prev->degree()-2 ) ) )
79 curr->selectPoint( 0, m_select );
80 }
81 }
82 }
83
84 if( m_rect.contains( curr->knot() ) )
85 {
86 curr->selectKnot( m_select );
87 // select the last control point before the knot, if segment is curve
88 if( curr->isCurve() && m_select )
89 curr->selectPoint( curr->degree()-2 );
90
91 setSuccess();
92 }
93 }
94 curr = curr->next();
95 }
96 // select first node as well
97 if( path.isClosed() && path.getLast()->knotIsSelected() )
98 path.getFirst()->selectKnot( m_select );
99}
100
101void
102VSelectNodes::visitVLayer( VLayer& layer )
103{
104 VDocument* doc = (VDocument*)layer.parent();
105 if ( ( layer.state() != VObject::deleted ) &&
106 ( ( doc->selectionMode() == VDocument::AllLayers ) ||
107 ( doc->selectionMode() == VDocument::VisibleLayers && ( layer.state() == VObject::normal || layer.state() == VObject::normal_locked ) ) ||
108 ( doc->selectionMode() == VDocument::SelectedLayers && layer.selected() ) ||
109 ( doc->selectionMode() == VDocument::ActiveLayer && doc->activeLayer() == &layer ) ) )
110 {
111 VObjectListIterator itr( layer.objects() );
112 for( ; itr.current(); ++itr )
113 itr.current()->accept( *this );
114 }
115}
116
117void
118VTestNodes::visitVSubpath( VSubpath& path )
119{
120 path.first();
121
122 while( path.current() )
123 {
124 for( int i = 0; i < path.current()->degree(); i++ )
125 if( m_rect.contains( path.current()->point( i ) ) ) //&&
126 //path.current()->pointIsSelected( i ) )
127 {
128 m_segments.append( path.current() );
129 setSuccess();
130 // only add a segment once
131 break;
132 }
133
134 path.next();
135 }
136}
137
138void
139VTestNodes::visitVLayer( VLayer& layer )
140{
141 VDocument* doc = (VDocument*)layer.parent();
142 if ( ( layer.state() != VObject::deleted ) &&
143 ( ( doc->selectionMode() == VDocument::AllLayers ) ||
144 ( doc->selectionMode() == VDocument::VisibleLayers && ( layer.state() == VObject::normal || layer.state() == VObject::normal_locked ) ) ||
145 ( doc->selectionMode() == VDocument::SelectedLayers && layer.selected() ) ||
146 ( doc->selectionMode() == VDocument::ActiveLayer && doc->activeLayer() == &layer ) ) )
147 {
148 VObjectListIterator itr( layer.objects() );
149 for( ; itr.current(); ++itr )
150 itr.current()->accept( *this );
151 }
152}
153
VLayer * activeLayer() const
Returns a pointer to the active layer.
Definition vdocument.h:212
@ AllLayers
selection within all layers
Definition vdocument.h:60
@ ActiveLayer
selection within the active layer
Definition vdocument.h:57
@ VisibleLayers
selection within all visible layers
Definition vdocument.h:58
@ SelectedLayers
selection within all selected layers
Definition vdocument.h:59
VSelectionMode selectionMode()
Returns the selection mode.
Definition vdocument.h:246
const VObjectList & objects() const
Read only access to the grouped objects.
Definition vgroup.h:110
VLayer manages a set of vobjects.
Definition vlayer.h:37
bool selected()
Returns the selection state of the layer.
Definition vlayer.h:115
VObject * parent() const
Returns pointer to current parent object.
Definition vobject.h:147
@ normal_locked
visible, but locked (r/o)
Definition vobject.h:55
@ deleted
deleted, nearly dead
Definition vobject.h:58
@ normal
visible, not active
Definition vobject.h:54
VState state() const
Get the state the object is in.
Definition vobject.h:154
bool pointIsSelected(int i) const
Returns true if the point with index 0 <= i < degree() is selected.
Definition vsegment.h:173
bool knotIsSelected() const
Returns true if the knot is selected.
Definition vsegment.h:181
VSegment * next() const
Returns a pointer to the next not deleted segment, if stored in a VSubpath.
bool isSmooth(const VSegment &next) const
Calculates wether the tangent at the knot is exactly parallel to the tangent at p0 of the next segmen...
Definition vsegment.cpp:700
void selectKnot(bool select=true)
Selects/deselects the knot of this segment.
Definition vsegment.h:197
void selectPoint(int i, bool select=true)
Selects the point with index 0 <= i < degree().
Definition vsegment.h:189
VSegment * prev() const
Returns a pointer to the previous not deleted segment, if stored in a VSubpath.
unsigned short degree() const
Returns the segment's degree, which is identical to the number of nodes.
Definition vsegment.h:77
const KoPoint & point(int i) const
Returns the segment's point with index 0 <= i < degree().
Definition vsegment.h:115
const KoPoint & knot() const
Returns the knot.
Definition vsegment.h:135
VSubpath provides a sophisticated list of VSegment.
Definition vpath.h:43
void setSuccess(bool success=true)
Set the success property.
Definition vvisitor.h:142