karbon

vselectnodes.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, The Karbon Developers
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 
00021 #include "vpath.h"
00022 #include "vsegment.h"
00023 #include "vselectnodes.h"
00024 #include "vlayer.h"
00025 #include "vdocument.h"
00026 
00027 void
00028 VSelectNodes::visitVSubpath( VSubpath& path )
00029 {
00030     path.first();
00031 
00032     VSegment *curr = path.current();
00033 
00034     while( curr )
00035     {
00036         if( m_rect.isEmpty() )
00037         {
00038             for( int i = 0; i < curr->degree(); i++ )
00039                 curr->selectPoint( i, m_select );
00040 
00041             setSuccess();
00042         }
00043         else
00044         {
00045             if( m_exclusive )
00046             {
00047                 // we are in exclusive mode, so deselect all nodes first
00048                 for( int i = 0; i < curr->degree(); i++ )
00049                     curr->selectPoint( i, false );
00050             }
00051 
00052             if( curr->isCurve() )
00053             {
00054                 // select all control points inside the selection rect
00055                 for( int i = 0; i < curr->degree()-1; ++i )
00056                 {
00057                     if( m_rect.contains( curr->point( i ) ) )
00058                     {
00059                         curr->selectPoint( i, m_select );
00060                         setSuccess();
00061                     }
00062                 }
00063                 VSegment* prev = curr->prev();
00064                 // make sure the last control point of the previous segment and the first control point
00065                 // of the current segment are selected if:
00066                 // - both segments are curves with a smooth transition and
00067                 // - the previous segment's knot is selected or
00068                 // - one of the above mentioned control points is already selected
00069                 if( prev )
00070                 {
00071                     if( curr->pointIsSelected( 0 ) == m_select )
00072                     {
00073                         if( prev->isCurve() && prev->isSmooth() )
00074                             prev->selectPoint( prev->degree()-2, m_select );
00075                     }
00076                     else
00077                     {
00078                         if( prev->knotIsSelected() || ( prev->isCurve() && prev->isSmooth() && prev->pointIsSelected( prev->degree()-2 ) ) )
00079                             curr->selectPoint( 0, m_select );
00080                     }
00081                 }
00082             }   
00083 
00084             if( m_rect.contains( curr->knot() ) )
00085             {
00086                 curr->selectKnot( m_select );
00087                 // select the last control point before the knot, if segment is curve
00088                 if( curr->isCurve() && m_select )
00089                     curr->selectPoint( curr->degree()-2 );
00090 
00091                 setSuccess();
00092             }
00093         }
00094         curr = curr->next();
00095     }
00096     // select first node as well
00097     if( path.isClosed() && path.getLast()->knotIsSelected() )
00098         path.getFirst()->selectKnot( m_select );
00099 }
00100 
00101 void
00102 VSelectNodes::visitVLayer( VLayer& layer )
00103 {
00104     VDocument* doc = (VDocument*)layer.parent();
00105     if ( ( layer.state() != VObject::deleted ) &&
00106          ( ( doc->selectionMode() == VDocument::AllLayers ) ||
00107            ( doc->selectionMode() == VDocument::VisibleLayers && ( layer.state() == VObject::normal || layer.state() == VObject::normal_locked ) ) ||
00108            ( doc->selectionMode() == VDocument::SelectedLayers && layer.selected() ) ||
00109            ( doc->selectionMode() == VDocument::ActiveLayer && doc->activeLayer() == &layer ) ) )
00110     {
00111         VObjectListIterator itr( layer.objects() );
00112         for( ; itr.current(); ++itr )
00113             itr.current()->accept( *this );
00114     }
00115 }
00116 
00117 void
00118 VTestNodes::visitVSubpath( VSubpath& path )
00119 {
00120     path.first();
00121 
00122     while( path.current() )
00123     {
00124         for( int i = 0; i < path.current()->degree(); i++ )
00125             if( m_rect.contains( path.current()->point( i ) ) ) //&&
00126               //path.current()->pointIsSelected( i ) )
00127             {
00128                 m_segments.append( path.current() );
00129                 setSuccess();
00130                 // only add a segment once
00131                 break;
00132             }
00133 
00134         path.next();
00135     }
00136 }
00137 
00138 void
00139 VTestNodes::visitVLayer( VLayer& layer )
00140 {
00141     VDocument* doc = (VDocument*)layer.parent();
00142     if ( ( layer.state() != VObject::deleted ) &&
00143          ( ( doc->selectionMode() == VDocument::AllLayers ) ||
00144            ( doc->selectionMode() == VDocument::VisibleLayers && ( layer.state() == VObject::normal || layer.state() == VObject::normal_locked ) ) ||
00145            ( doc->selectionMode() == VDocument::SelectedLayers && layer.selected() ) ||
00146            ( doc->selectionMode() == VDocument::ActiveLayer && doc->activeLayer() == &layer ) ) )
00147     {
00148         VObjectListIterator itr( layer.objects() );
00149         for( ; itr.current(); ++itr )
00150             itr.current()->accept( *this );
00151     }
00152 }
00153 
KDE Home | KDE Accessibility Home | Description of Access Keys