00001 #include "vectoreditor.h" 00002 #include "TraceLog.h" 00003 00004 VectorEditor::VectorEditor( VectorLayerSet *lyrset, 00005 ViewSet *viewset ) : 00006 mLayerSet( lyrset ), 00007 mViewSet( viewset ) { 00008 mData = NULL; 00009 mSelSet = NULL; 00010 init(); 00011 00012 connect( lyrset, 00013 SIGNAL( activeLayerChanged( int ) ), 00014 this, 00015 SLOT( activeLayerChanged( int ) ) ); 00016 } 00017 00018 VectorEditor::~VectorEditor( ) {;} 00019 00020 void VectorEditor::addView( View *view ) { 00021 connect( view, 00022 SIGNAL( viewMouseMove( QMouseEvent *, View::MouseState & ) ), 00023 this, 00024 SLOT( viewMouseMove( QMouseEvent *, View::MouseState & ) ) ); 00025 00026 connect( view, 00027 SIGNAL( viewMousePress( QMouseEvent *, View::MouseState & ) ), 00028 this, 00029 SLOT( viewMousePress( QMouseEvent *, View::MouseState & ) ) ); 00030 00031 connect( view, 00032 SIGNAL( viewMouseRelease( QMouseEvent *, View::MouseState & ) ), 00033 this, 00034 SLOT( viewMouseRelease( QMouseEvent *, View::MouseState & ) ) ); 00035 00036 connect( view, 00037 SIGNAL( viewKeyPress( QKeyEvent * ) ), 00038 this, 00039 SLOT( viewKeyPress( QKeyEvent * ) ) ); 00040 00041 connect( view, 00042 SIGNAL( viewKeyRelease( QKeyEvent * ) ), 00043 this, 00044 SLOT( viewKeyRelease( QKeyEvent * ) ) ); 00045 } 00046 00047 void VectorEditor::removeView( View *view ) { 00048 disconnect( view, 00049 SIGNAL( viewMouseMove( QMouseEvent *, View::MouseState & ) ), 00050 this, 00051 SLOT( viewMouseMove( QMouseEvent *, View::MouseState & ) ) ); 00052 00053 disconnect( view, 00054 SIGNAL( viewMousePress( QMouseEvent *, View::MouseState & ) ), 00055 this, 00056 SLOT( viewMousePress( QMouseEvent *, View::MouseState & ) ) ); 00057 00058 disconnect( view, 00059 SIGNAL( viewMouseRelease( QMouseEvent *, View::MouseState & ) ), 00060 this, 00061 SLOT( viewMouseRelease( QMouseEvent *, View::MouseState & ) ) ); 00062 00063 disconnect( view, 00064 SIGNAL( viewKeyPress( QKeyEvent * ) ), 00065 this, 00066 SLOT( viewKeyPress( QKeyEvent * ) ) ); 00067 00068 disconnect( view, 00069 SIGNAL( viewKeyRelease( QKeyEvent * ) ), 00070 this, 00071 SLOT( viewKeyRelease( QKeyEvent * ) ) ); 00072 } 00073 00074 void VectorEditor::init( ) { 00075 mInObject = false; 00076 mCtrlDown = false; 00077 mShiftDown = false; 00078 mMovingNode = false; 00079 mOverNode.clear(); 00080 } 00081 00082 std::vector<SelectionSet::SelObj> VectorEditor::overSelNode( double x, double y ) { 00083 std::vector<SelectionSet::SelObj> selobjset; 00084 if ( mSelSet == NULL ) return selobjset; 00085 SelectionSet &refSelSet = *mSelSet; 00086 if ( !mData ) 00087 return selobjset; 00088 00089 std::vector<Shape*> &xyset = mData->getXYSet(); 00090 00091 if ( mData->getType() == VectorData::POINT ) { 00092 for ( int iselobj=0; iselobj < refSelSet.size(); iselobj++ ) { 00093 Shape &s = *xyset[refSelSet[iselobj].obj]; 00094 Node &n = dynamic_cast<Node&>( s ); 00095 if ( fabs( n.x - x ) < 3 ) { 00096 if ( fabs( n.y - y ) < 3 ) { 00097 SelectionSet::SelObj selobj; 00098 selobj.obj = refSelSet[iselobj].obj; 00099 selobjset.push_back( selobj ); 00100 } 00101 } 00102 } 00103 return selobjset; 00104 } 00105 00106 for ( int iselobj=0; iselobj < refSelSet.size(); iselobj++ ) { 00107 Shape &s = *xyset[refSelSet[iselobj].obj]; 00108 Line &l = dynamic_cast<Line&>( s ); 00109 for ( int inode=0; inode < (int)l.size(); inode++ ) { 00110 if ( fabs( l[inode].x - x ) < 3 ) { 00111 if ( fabs( l[inode].y - y ) < 3 ) { 00112 SelectionSet::SelObj selobj; 00113 selobj.obj = refSelSet[iselobj].obj; 00114 selobj.nodes.push_back( inode ); 00115 selobjset.push_back( selobj ); 00116 } 00117 } 00118 } 00119 } 00120 00121 return selobjset; 00122 } 00123 00124 void VectorEditor::viewMousePress( QMouseEvent *me, 00125 View::MouseState &ms ) { 00126 if ( !mData ) 00127 return; 00128 00129 if ( mSelSet == NULL ) return; 00130 SelectionSet &refSelSet = *mSelSet; 00131 00132 switch ( View::mTool ) { 00133 case View::LINE: // viewMousePress 00134 if ( me->button() == Qt::LeftButton ) { 00135 // CONTINUING A LINE 00136 if ( refSelSet.size() == 1 && refSelSet[0].nodes.size() == 1 ) { 00137 if ( refSelSet.size() != 1 ) { 00138 char *msg = "There must be only one node in one line selected to add nodes"; 00139 QMessageBox::information( NULL, 00140 "Editor Error", 00141 msg ); 00142 break; 00143 } 00144 mData->push(); 00145 00146 Node node; 00147 node.x = ms.mCurPos.x; 00148 node.y = ms.mCurPos.y; 00149 node.z = 0; 00150 00151 if ( !mCtrlDown ) { 00152 mData->addLineNode( node, refSelSet[0].obj, refSelSet[0].nodes[0] ); 00153 // INC THE NODE INDEX SO NEW NODE IS ACTIVE 00154 refSelSet[0].nodes[0]++; 00155 } else { 00156 // SELECTION NODE INDEX STAYS THE SAME HERE 00157 mData->insertLineNode( node, refSelSet[0].obj, refSelSet[0].nodes[0] ); 00158 } 00159 } 00160 // STARTING A NEW LINE 00161 else if ( refSelSet.size() == 0 || refSelSet.size() > 1) { 00162 if (refSelSet.size() > 1) { 00163 refSelSet.clear() ; 00164 } 00165 mData->push(); 00166 mInObject = true; 00167 Node node; 00168 node.x = ms.mCurPos.x; 00169 node.y = ms.mCurPos.y; 00170 mData->addLine( node ); 00171 //refSelSet.clear(); 00172 clearAllLayerSelections () ; 00173 SelectionSet::SelObj selobj; 00174 selobj.obj = mData->size() - 1; 00175 selobj.nodes.push_back( 0 ); 00176 refSelSet.add( selobj ); 00177 } 00178 00179 mViewSet->repaintViews(); 00180 } 00181 // FINISH A LINE 00182 else if ( me->button() == Qt::RightButton ) { 00183 00184 mData->pushSelection(); 00185 Shape &s = *mData->getXYSet()[refSelSet[0].obj]; 00186 Line &l = dynamic_cast<Line&>( s ); 00187 if ( (int)refSelSet.size() == 1 && 00188 (int)refSelSet[0].nodes.size() == 1 && 00189 refSelSet[0].nodes[0] == (int)l.size()-1 && 00190 mCtrlDown ) { 00191 Shape &s = *mData->getXYSet()[refSelSet[0].obj]; 00192 Line &l = dynamic_cast<Line&>( s ); 00193 mData->addLineNode( l[0], refSelSet[0].obj ); 00194 } 00195 mInObject = false; 00196 //refSelSet.clear(); 00197 clearAllLayerSelections () ; 00198 mViewSet->repaintViews(); 00199 } 00200 break; 00201 00202 case View::GLACIER_ID: 00203 { 00204 mData->push(); 00205 Node node; 00206 node.x = ms.mCurPos.x; 00207 node.y = ms.mCurPos.y; 00208 node.z = 0; 00209 mData->addNode( node ); 00210 mViewSet->repaintViews(); 00211 00212 emit selectionChanged() ; 00213 } 00214 break; 00215 00216 case View::POINTER: 00217 break; 00218 00219 case View::SELECTION: // viewMousePress 00220 if ( mOverNode.size() ) { 00221 mMovingNode = true; 00222 00223 //refSelSet.clear(); 00224 clearAllLayerSelections () ; 00225 refSelSet.add( mOverNode[0] ); 00226 } 00227 else { 00228 // push history of selection before clearing selection 00229 // and setting selection to the current node 00230 mData->push(); 00231 mData->pushSelection(); 00232 00233 SelectionSet::SelBox &box = refSelSet.selBox(); 00234 box.x = ms.mCurPos.x; 00235 box.y = ms.mCurPos.y; 00236 box.w = 0; 00237 box.h = 0; 00238 refSelSet.setSelecting( true ); 00239 } 00240 mViewSet->repaintViews(); 00241 00242 emit selectionChanged() ; 00243 00244 break; 00245 00246 default: 00247 break; 00248 } 00249 } 00250 00251 void VectorEditor::viewMouseMove( QMouseEvent *, 00252 View::MouseState &ms ) { 00253 00254 if ( mSelSet == NULL )return; 00255 SelectionSet &refSelSet = *mSelSet; 00256 00257 if ( !mData ) 00258 return; 00259 00260 switch ( View::mTool ) { 00261 case View::LINE: 00262 break; 00263 00264 case View::GLACIER_ID: 00265 break; 00266 00267 case View::POINTER: 00268 break; 00269 00270 case View::SELECTION: 00271 if ( mMovingNode ) { 00272 if ( mCtrlDown ) { 00273 for ( int iobj=0; iobj < (int)mOverNode.size(); iobj++ ) { 00274 int obj = mOverNode[iobj].obj; 00275 int n = -1; 00276 if ( mData->getType() != VectorData::POINT ) 00277 n = mOverNode[iobj].nodes[0]; 00278 00279 Node node; 00280 node.x = ms.mCurPos.x; 00281 node.y = ms.mCurPos.y; 00282 mData->moveLineNode( obj, n, node ); 00283 } 00284 } else { 00285 Node node; 00286 node.x = ms.mCurPos.x; 00287 node.y = ms.mCurPos.y; 00288 if ( mData->getType() != VectorData::POINT ) 00289 mData->moveLineNode( mOverNode[0].obj, mOverNode[0].nodes[0], node ); 00290 else 00291 mData->moveNode( node, mOverNode[0].obj ); 00292 } 00293 00294 mViewSet->repaintViews(); 00295 00296 emit selectionChanged() ; 00297 } else { 00298 mOverNode = overSelNode( ms.mCurPos.x, ms.mCurPos.y ); 00299 if ( mOverNode.size() ) { 00300 QApplication::setOverrideCursor( Qt::crossCursor, true ); 00301 } else { 00302 QApplication::setOverrideCursor( Qt::arrowCursor, true ); 00303 } 00304 } 00305 00306 if ( !mMovingNode && refSelSet.isSelecting() ) { 00307 // THIS CHANGES THE SELECTION BOX FOR THE VIEWS, BUT I THINK 00308 // THIS SHOULD BE DONE IN THE VIEW CLASS ITSELF OR MAKE THE 00309 // SELECTBOX DIMENSIONS STATIC AND CHANGE THEM DIRECTLY FROM 00310 // HERE, BUT THEN WHAT'S THE POINT. 00311 SelectionSet::SelBox &box = refSelSet.selBox(); 00312 Rect dim; 00313 dim.x = _int_min( (int)box.x, (int)ms.mCurPos.x ); 00314 dim.y = _int_min( (int)box.y, (int)ms.mCurPos.y ); 00315 dim.w = _int_max( (int)box.x, (int)ms.mCurPos.x ) - dim.x; 00316 dim.h = _int_max( (int)box.y, (int)ms.mCurPos.y ) - dim.y; 00317 00318 mViewSet->setSelBox( dim ); 00319 mViewSet->repaintViews(); 00320 00321 emit selectionChanged() ; 00322 } 00323 break; 00324 00325 default: 00326 break; 00327 } 00328 00329 } 00330 00331 void VectorEditor::viewMouseRelease( QMouseEvent *, 00332 View::MouseState &ms ) { 00333 if ( !mData ) 00334 return; 00335 00336 if ( mSelSet == NULL ) return; 00337 SelectionSet &refSelSet = *mSelSet; 00338 00339 switch ( View::mTool ) { 00340 case View::LINE: 00341 break; 00342 00343 case View::GLACIER_ID: 00344 break; 00345 00346 case View::POINTER: 00347 break; 00348 00349 case View::SELECTION: // viewMouseRelease 00350 // if user was moving a node, set this action to stopped 00351 if ( mMovingNode ) { 00352 mMovingNode = false; 00353 } 00354 // otherwise, the user has completed creating a selection box 00355 else { 00356 if ( refSelSet.isSelecting() ) { 00357 SelectionSet::SelBox &boxref = refSelSet.selBox(); 00358 SelectionSet::SelBox box = boxref; 00359 00360 boxref.x = _int_min( (int)box.x, (int)ms.mCurPos.x ); 00361 boxref.y = _int_min( (int)box.y, (int)ms.mCurPos.y ); 00362 boxref.w = _int_max( (int)box.x, (int)ms.mCurPos.x ) - boxref.x; 00363 boxref.h = _int_max( (int)box.y, (int)ms.mCurPos.y ) - boxref.y; 00364 00365 viewSelChanged( refSelSet.selBox() ); 00366 refSelSet.resetBox(); 00367 00368 Rect dim; 00369 dim.x = dim.y = dim.w = dim.h = 0; 00370 mViewSet->setSelBox( dim ); 00371 mViewSet->repaintViews(); 00372 00373 emit selectionChanged() ; 00374 } 00375 } 00376 break; 00377 00378 default: 00379 break; 00380 } 00381 00382 } 00383 00384 void VectorEditor::viewKeyPress( QKeyEvent *ke ) { 00385 if ( !mData ) 00386 return; 00387 00388 switch ( ke->key() ) { 00389 // user hit SHIFT key 00390 case Qt::Key_Shift: 00391 mShiftDown = true; 00392 break; 00393 00394 // user hit CONTROL key 00395 case Qt::Key_Control: 00396 mCtrlDown = true; 00397 break; 00398 00399 // user hit DELETE key 00400 case Qt::Key_Delete: 00401 mData->push(); 00402 delSel(); 00403 break; 00404 00405 // user hit B to BREAK LINE (disabled) 00406 case Qt::Key_B: 00407 if ( mCtrlDown ) { 00408 // mData->breakLine( ); 00409 mViewSet->repaintViews(); 00410 emit selectionChanged() ; 00411 } 00412 break; 00413 00414 // user hit Z to UNDO or REDO 00415 case Qt::Key_Z: 00416 if ( mCtrlDown && mShiftDown) { // REDO Shift-Z 00417 mData->redo(); 00418 mViewSet->repaintViews(); 00419 emit selectionChanged() ; 00420 } 00421 else if ( mCtrlDown ) { // UNDO Z 00422 mData->pop(); 00423 mViewSet->repaintViews(); 00424 emit selectionChanged() ; 00425 } 00426 break; 00427 00428 // user hit Y to REDO 00429 case Qt::Key_Y: 00430 if ( mCtrlDown ) { 00431 mData->redo(); 00432 mViewSet->repaintViews(); 00433 emit selectionChanged() ; 00434 } 00435 break; 00436 00437 default: 00438 break; 00439 } 00440 00441 } 00442 00443 void VectorEditor::viewKeyRelease( QKeyEvent *ke ) { 00444 switch ( ke->key() ) { 00445 case Qt::Key_Shift: 00446 mShiftDown = false; 00447 break; 00448 00449 case Qt::Key_Control: 00450 mCtrlDown = false; 00451 break; 00452 00453 default: 00454 break; 00455 } 00456 00457 } 00458 00459 void VectorEditor::viewSelChanged( SelectionSet::SelBox &box ) { 00460 // if there are no vector data, return 00461 if ( !mData ) 00462 return; 00463 00464 // if there is no selection set (data selected), return 00465 if ( mSelSet == NULL ) 00466 return; 00467 00468 SelectionSet &refSelSet = *mSelSet; // make copy of the selection set 00469 int ipnt; 00470 std::vector<Shape*> &objset = mData->getXYSet(); // get the vector data 00471 00472 // clear current selection if the shift-key's not depressed 00473 if ( !mShiftDown ) { 00474 //refSelSet.clear(); 00475 clearAllLayerSelections () ; 00476 } 00477 00478 // if the data are point data... 00479 if ( mData->getType() == VectorData::POINT ) { 00480 //...for each point... 00481 for ( int iobj = 0; iobj < (int)objset.size(); iobj++ ) { 00482 Shape &s = *objset[iobj]; 00483 Node &n = dynamic_cast<Node&>( s ); 00484 int x = (int)n.x; 00485 int y = (int)n.y; 00486 // check to see if point is inside the selection box 00487 if ( x > box.x && x < (box.x + box.w) && 00488 y > box.y && y < (box.y + box.h) ) { 00489 // ...and add this point to the selected vector data 00490 // (apparently do the same thing no matter what) 00491 if ( mShiftDown && !isSelLine( iobj ) ) { 00492 SelectionSet::SelObj selobj; 00493 selobj.obj = iobj; 00494 refSelSet.add( selobj ); 00495 } 00496 else { 00497 SelectionSet::SelObj selobj; 00498 selobj.obj = iobj; 00499 refSelSet.add( selobj ); 00500 } 00501 } 00502 } 00503 } 00504 00505 // if the data are not point data, apparently, they're line data 00506 else { 00507 // for each line... 00508 for ( int iline = 0 ; iline < (int)objset.size() ; iline++ ) { 00509 Shape &s = *objset[iline]; 00510 Line &l = dynamic_cast<Line&>( s ); 00511 // for each node (vertex) in the line... 00512 for ( ipnt = 0 ; ipnt < (int)l.size() ; ipnt++ ) { 00513 Node n = l[ipnt]; 00514 int x = (int)n.x; 00515 int y = (int)n.y; 00516 // if the node is in the selection box... 00517 if ( x > box.x && x < (box.x + box.w) && 00518 y > box.y && y < (box.y + box.h) ) { 00519 int il = iline, ip = ipnt; 00520 // if this node in the line isn't already selected... 00521 if ( !isSelPoint( il, ip ) ) { 00522 // if this line isn't already selected, put it in the selection list 00523 if ( il == -1 ) { 00524 SelectionSet::SelObj selobj; 00525 selobj.obj = iline; 00526 // selobj.nodes.push_back( ipnt ); 00527 refSelSet.add( selobj ); 00528 refSelSet[refSelSet.size()-1].nodes.push_back( ipnt ); 00529 } 00530 // otherwise... 00531 else { 00532 refSelSet[il].nodes.push_back( ipnt ); 00533 } 00534 } 00535 } 00536 } 00537 00538 // if this line isn't selected already, 00539 // check to see if it intersects the selection box 00540 // (i.e. no nodes fell in the selection box, but the line does) 00541 if ( isSelLine( iline ) == -1 ) { 00542 // for each line segment in the line... 00543 for ( ipnt = 1 ; ipnt < (int)l.size() ; ipnt++ ) { 00544 Node p1, p2; 00545 Node bp1, bp2, bp3, bp4; 00546 00547 bp1.x = box.x; // UL 00548 bp1.y = box.y; 00549 bp2.x = box.x; // LL 00550 bp2.y = box.y + box.h; 00551 bp3.x = box.x + box.w; // LR 00552 bp3.y = bp2.y; 00553 bp4.x = bp3.x; // UR 00554 bp4.y = box.y; 00555 00556 p1 = l[ ipnt-1 ]; 00557 p2 = l[ ipnt ]; 00558 00559 // does this line segment intersect the selection box? 00560 if ( hasIntersect( p1, p2, bp1, bp2 ) || 00561 hasIntersect( p1, p2, bp2, bp3 ) || 00562 hasIntersect( p1, p2, bp3, bp4 ) || 00563 hasIntersect( p1, p2, bp4, bp1 ) ) { 00564 SelectionSet::SelObj selobj; 00565 selobj.obj = iline; 00566 refSelSet.add( selobj ); 00567 } 00568 } 00569 } 00570 } 00571 } 00572 00573 mViewSet->repaintViews(); 00574 emit selectionChanged() ; 00575 } 00576 00577 void VectorEditor::breakLine( ) { 00578 if ( !mData ) return; 00579 if ( mSelSet == NULL )return; 00580 00581 SelectionSet &refSelSet = *mSelSet; 00582 00583 int sel1, nod1; 00584 std::vector<Shape*> &shpset = mData->getXYSet(); 00585 00586 if ( refSelSet.size() != 1 ) { 00587 QMessageBox::information( NULL, 00588 "Join Line Error", 00589 "There must be only one line selected" ); 00590 return; 00591 } 00592 00593 if ( refSelSet[0].nodes.size() != 1 ) { 00594 QMessageBox::information( NULL, 00595 "Join Line Error", 00596 "There must be one point selected in one line" ); 00597 return; 00598 } 00599 00600 sel1 = refSelSet[0].obj; 00601 if ( sel1 < 0 || sel1 >= (int)shpset.size() ) 00602 return; 00603 00604 Shape &s1 = *shpset[ sel1 ]; 00605 Line &l1 = dynamic_cast<Line&>( s1 ); 00606 00607 nod1 = refSelSet[0].nodes[0]; 00608 if ( nod1 <= 0 || nod1 >= (int)l1.size()-1 ) { 00609 QMessageBox::information( NULL, 00610 "Join Line Error", 00611 "There must be one point selected in one line" ); 00612 return; 00613 } 00614 00615 mData->breakLine( sel1, nod1 ); 00616 mViewSet->repaintViews(); 00617 emit selectionChanged() ; 00618 } 00619 00620 void VectorEditor::joinLine( ) { 00621 if ( !mData ) return; 00622 if ( mSelSet == NULL )return; 00623 SelectionSet &refSelSet = *mSelSet; 00624 00625 int sel1, sel2, nod1, nod2; 00626 std::vector<Shape*> &shpset = mData->getXYSet(); 00627 00628 if ( refSelSet.size() != 2 ) { 00629 QMessageBox::information( NULL, 00630 "Join Line Error", 00631 "There must be two lines selected" ); 00632 return; 00633 } 00634 00635 // huh? repetition of above check 00636 if ( refSelSet.size() != 2 ) { 00637 QMessageBox::information( NULL, 00638 "Join Line Error", 00639 "There must be two end points selected in two lines" ); 00640 return; 00641 } 00642 00643 sel1 = refSelSet[0].obj; 00644 sel2 = refSelSet[1].obj; 00645 if ( sel1 < 0 || sel1 >= (int)shpset.size() || 00646 sel2 < 0 || sel2 >= (int)shpset.size() ) 00647 return; 00648 00649 Shape &s1 = *shpset[ sel1 ]; 00650 Shape &s2 = *shpset[ sel2 ]; 00651 00652 Line &l1 = dynamic_cast<Line&>( s1 ); 00653 Line &l2 = dynamic_cast<Line&>( s2 ); 00654 00655 nod1 = refSelSet[0].nodes[0]; 00656 nod2 = refSelSet[1].nodes[0]; 00657 if ( !(nod1 == 0 || nod1 == (int)l1.size()-1) || 00658 !(nod2 == 0 || nod2 == (int)l2.size()-1) ) { 00659 QMessageBox::information( NULL, 00660 "Join Line Error", 00661 "There must be two end points selected in two lines" ); 00662 return; 00663 } 00664 00665 mData->pushSelection(); 00666 mSelSet->erase(1) ; 00667 mData->joinLine( sel1, sel2, nod1, nod2 ); 00668 00669 00670 mViewSet->repaintViews(); 00671 emit selectionChanged() ; 00672 00673 } 00674 00675 void VectorEditor::contLine( ) { 00676 /* 00677 if( !mData ) 00678 return; 00679 00680 std::vector<Line> &xyobjset = mLayer->getXYObjSet(); 00681 00682 if( refSelSet.size() != 1 || 00683 refSelSet[0].nodes.size() != 1 ) 00684 { 00685 QMessageBox::information( 00686 NULL, 00687 "", 00688 "There must be one node selected to continue a line" ); 00689 } 00690 00691 */ 00692 00693 } 00694 00695 void VectorEditor::delSel( ) { 00696 if ( !mData ) return; 00697 00698 if ( mSelSet == NULL ) return; 00699 SelectionSet &refSelSet = *mSelSet; 00700 00701 // delete a point 00702 if ( mData->getType() == VectorData::POINT ) { 00703 00704 // for each SelObj to be deleted in the SelectionSet 00705 for ( int isel = 0 ; isel < (int)refSelSet.size() ; isel++ ) { 00706 00707 // for each SelObj remaining in the SelectionSet 00708 for ( int i = 0 ; i < (int)refSelSet.size() ; i++ ) { 00709 00710 // compare the objs in the SelObjs, and 00711 // bump the remaining ones down a notch if they're 00712 // greater than the one to be deleted 00713 if ( refSelSet[isel].obj < refSelSet[i].obj ) { 00714 refSelSet[i].obj--; 00715 } 00716 00717 } // end for the remining SelObjs 00718 mData->delNode( refSelSet[isel].obj ); 00719 00720 } // end for the SelObjs to be deleted 00721 clearAllLayerSelections () ; 00722 00723 } 00724 00725 // delete a line 00726 else { 00727 int szLine = 0; 00728 for ( int isel=0; isel < (int)refSelSet.size(); isel++ ) { 00729 Shape &s = *mData->getXYSet()[ refSelSet[isel].obj ]; 00730 Line &l = dynamic_cast<Line&>( s ); 00731 szLine = l.size(); 00732 if ( mCtrlDown || szLine <= (int)refSelSet[isel].nodes.size() ) { 00733 for ( int i=0; i < (int)refSelSet.size(); i++ ) { 00734 if ( refSelSet[isel].obj < refSelSet[i].obj ) { 00735 refSelSet[i].obj--; 00736 } 00737 } 00738 mData->delLine( refSelSet[isel].obj ); 00739 } 00740 else { 00741 sort( refSelSet[isel].nodes.begin(), refSelSet[isel].nodes.end() ); 00742 for ( int inode=refSelSet[isel].nodes.size()-1; inode > -1; inode-- ) { 00743 mData->delLineNode( refSelSet[isel].obj, refSelSet[isel].nodes[inode] ); 00744 } 00745 } 00746 } 00747 00748 if ( !mCtrlDown && refSelSet.size() == 1 && refSelSet[0].nodes.size() == 1 ) { 00749 if ( refSelSet[0].nodes[0] >= szLine-1 ) { 00750 refSelSet[0].nodes[0]--; 00751 } 00752 if ( refSelSet[0].nodes[0] < 0 ) { 00753 clearAllLayerSelections () ; 00754 } 00755 } 00756 else { 00757 clearAllLayerSelections () ; 00758 } 00759 } 00760 00761 mViewSet->repaintViews(); 00762 emit selectionChanged() ; 00763 00764 } 00765 00766 bool VectorEditor::hasIntersect( Node p1, 00767 Node p2, 00768 Node p3, 00769 Node p4 ) { 00770 if ( p1.x - p2.x == 0 ) 00771 p1.x -= 0.01; 00772 if ( p3.x - p4.x == 0 ) 00773 p3.x -= 0.01; 00774 00775 double m1 = ( p1.y - p2.y ) / ( p1.x - p2.x ); 00776 double m2 = ( p3.y - p4.y ) / ( p3.x - p4.x ); 00777 00778 // PARRALEL 00779 if ( m1 == m2 ) 00780 return false; 00781 00782 double b1 = p1.y - m1 * p1.x; 00783 double b2 = p3.y - m2 * p3.x; 00784 00785 double ix = ( b1 - b2 ) / ( m2 - m1 ); 00786 00787 if ( p1.x < p2.x ) { 00788 if ( p1.x > ix || p2.x < ix ) 00789 return false; 00790 } else { 00791 if ( p2.x > ix || p1.x < ix ) 00792 return false; 00793 } 00794 00795 if ( p3.x < p4.x ) { 00796 if ( p3.x > ix || p4.x < ix ) 00797 return false; 00798 } else { 00799 if ( p4.x > ix || p3.x < ix ) 00800 return false; 00801 } 00802 00803 return true; 00804 } 00805 00806 int VectorEditor::isSelLine( int iline ) { 00807 if ( mSelSet == NULL )return -1; 00808 SelectionSet &refSelSet = *mSelSet; 00809 00810 for ( int i = 0 ; i < refSelSet.size() ; i++ ) { 00811 // look for SelectSet obj matching param iline 00812 // return index of SelectSet where iline is found 00813 // or -1 if not found 00814 if ( refSelSet[i].obj == iline ) 00815 return i; 00816 } 00817 return -1; 00818 } 00819 00820 bool VectorEditor::isSelPoint( int &il, int &ip ) { 00821 if ( mSelSet == NULL )return false; 00822 SelectionSet &refSelSet = *mSelSet; 00823 00824 int sl, sp; 00825 // if the line isn't in the Select Set, return -1 00826 if ( (sl = isSelLine( il )) == -1 ) { 00827 il = -1; 00828 ip = -1; 00829 return false; 00830 } 00831 00832 // set the line to the index it was found at in the SelectionSet 00833 il = sl; 00834 00835 // now, look for the matching Node in the Line represented by the SelObj (refSelSet[sl]) 00836 for ( sp = 0 ; sp < (int)refSelSet[sl].nodes.size() ; sp++ ) { 00837 if ( refSelSet[sl].nodes[sp] == ip ) 00838 break; 00839 } 00840 00841 // set the line to the index for that line in the SelectionSet 00842 // set the point to the index for that point from the Nodes array in the SelObj (refSelSet[sl]) 00843 // good job, return true 00844 if ( sp < (int)refSelSet[sl].nodes.size() ) { 00845 il = sl; 00846 ip = sp; 00847 return true; 00848 } 00849 00850 // point not found, bye-bye, return false 00851 ip = -1; 00852 return false; 00853 } 00854 00855 void VectorEditor::activeLayerChanged( int ilyr ) { 00856 if ( mLayerSet ) { 00857 VectorLayer *lyr = mLayerSet->getLayer( ilyr ); 00858 if ( lyr ) { 00859 mData = lyr->getData(); 00860 if ( mData ) 00861 mSelSet = &mData->getSelSet(); 00862 } 00863 } 00864 00865 } 00866 00867 void VectorEditor::clearAllLayerSelections() { 00868 if ( mLayerSet ) { 00869 for (unsigned int i = 0 ; i < mLayerSet->numLayers() ; i++) { 00870 VectorLayer *lyr = mLayerSet->getLayer( i ); 00871 if ( lyr ) { 00872 VectorData *vData = lyr->getData(); 00873 if ( vData ) { 00874 SelectionSet *nSelSet = &vData->getSelSet(); 00875 if (nSelSet && nSelSet->size()) { 00876 nSelSet->clear() ; 00877 emit selectionChanged() ; 00878 } 00879 } 00880 } 00881 } 00882 } 00883 } 00884 00885 00886 00887 00888 00889 00890 00891 00892
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |