summaryrefslogtreecommitdiffstats
path: root/karbon/visitors/vselectnodes.cpp
blob: 00f56de3966d0a0b0e83fbdb3966bfc8fc06d0cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* This file is part of the KDE project
   Copyright (C) 2002, The Karbon Developers

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/


#include "vpath.h"
#include "vsegment.h"
#include "vselectnodes.h"
#include "vlayer.h"
#include "vdocument.h"

void
VSelectNodes::visitVSubpath( VSubpath& path )
{
	path.first();

	VSegment *curr = path.current();

	while( curr )
	{
		if( m_rect.isEmpty() )
		{
			for( int i = 0; i < curr->degree(); i++ )
				curr->selectPoint( i, m_select );

			setSuccess();
		}
		else
		{
			if( m_exclusive )
			{
				// we are in exclusive mode, so deselect all nodes first
				for( int i = 0; i < curr->degree(); i++ )
					curr->selectPoint( i, false );
			}

			if( curr->isCurve() )
			{
				// select all control points inside the selection rect
				for( int i = 0; i < curr->degree()-1; ++i )
				{
					if( m_rect.contains( curr->point( i ) ) )
					{
						curr->selectPoint( i, m_select );
						setSuccess();
					}
				}
				VSegment* prev = curr->prev();
				// make sure the last control point of the previous segment and the first control point
				// of the current segment are selected if:
				// - both segments are curves with a smooth transition and
				// - the previous segment's knot is selected or
				// - one of the above mentioned control points is already selected
				if( prev )
				{
					if( curr->pointIsSelected( 0 ) == m_select )
					{
						if( prev->isCurve() && prev->isSmooth() )
							prev->selectPoint( prev->degree()-2, m_select );
					}
					else
					{
						if( prev->knotIsSelected() || ( prev->isCurve() && prev->isSmooth() && prev->pointIsSelected( prev->degree()-2 ) ) )
							curr->selectPoint( 0, m_select );
					}
				}
			}	

			if( m_rect.contains( curr->knot() ) )
			{
				curr->selectKnot( m_select );
				// select the last control point before the knot, if segment is curve
				if( curr->isCurve() && m_select )
					curr->selectPoint( curr->degree()-2 );

				setSuccess();
			}
		}
		curr = curr->next();
	}
	// select first node as well
	if( path.isClosed() && path.getLast()->knotIsSelected() )
		path.getFirst()->selectKnot( m_select );
}

void
VSelectNodes::visitVLayer( VLayer& layer )
{
	VDocument* doc = (VDocument*)layer.parent();
	if ( ( layer.state() != VObject::deleted ) &&
	     ( ( doc->selectionMode() == VDocument::AllLayers ) ||
	       ( doc->selectionMode() == VDocument::VisibleLayers && ( layer.state() == VObject::normal || layer.state() == VObject::normal_locked ) ) ||
	       ( doc->selectionMode() == VDocument::SelectedLayers && layer.selected() ) ||
	       ( doc->selectionMode() == VDocument::ActiveLayer && doc->activeLayer() == &layer ) ) )
	{
		VObjectListIterator itr( layer.objects() );
		for( ; itr.current(); ++itr )
			itr.current()->accept( *this );
	}
}

void
VTestNodes::visitVSubpath( VSubpath& path )
{
	path.first();

	while( path.current() )
	{
		for( int i = 0; i < path.current()->degree(); i++ )
			if( m_rect.contains( path.current()->point( i ) ) ) //&&
              //path.current()->pointIsSelected( i ) )
			{
				m_segments.append( path.current() );
				setSuccess();
				// only add a segment once
				break;
			}

		path.next();
	}
}

void
VTestNodes::visitVLayer( VLayer& layer )
{
	VDocument* doc = (VDocument*)layer.parent();
	if ( ( layer.state() != VObject::deleted ) &&
	     ( ( doc->selectionMode() == VDocument::AllLayers ) ||
	       ( doc->selectionMode() == VDocument::VisibleLayers && ( layer.state() == VObject::normal || layer.state() == VObject::normal_locked ) ) ||
	       ( doc->selectionMode() == VDocument::SelectedLayers && layer.selected() ) ||
	       ( doc->selectionMode() == VDocument::ActiveLayer && doc->activeLayer() == &layer ) ) )
	{
		VObjectListIterator itr( layer.objects() );
		for( ; itr.current(); ++itr )
			itr.current()->accept( *this );
	}
}