Пример #1
0
/**
 * Selects all circles (and arcs min. 3/4 circle) with same diameter and same layer,
 * in a window (v1, v2)
 * mosty used with CAM bores 
 *
 * @param e  Must be an circle or arc (min. 3/4 circle)
 */
void RS_Selection::selectCircles(RS_Entity* e, RS_Vector v1, RS_Vector v2 /*, bool inside=true */ ) 
{
   if (e==NULL) 
     return;
   
   if (!e->isAtomic()) 
     return;

   e->toggleSelected(); 
   
   // bool cross = v2.y > v1.y;
   
   bool cross = v1.x > v2.x;
   
   bool select = !e->isSelected();
   RS_AtomicEntity* ae = (RS_AtomicEntity*)e;
   double r_clicked = 0;
   RS_Layer* layer_clicked = 0;
   

   if (graphicView!=NULL) 
     graphicView->drawEntity(e);
   
   if (ae->rtti()==RS2::EntityArc || ae->rtti()==RS2::EntityCircle)
     {
	r_clicked = ae->getRadius();
	
	if (ae->rtti()==RS2::EntityArc)
	  if(ae->getAngleLength() < 4.66)   /* ca. 267 grad (knapp 3/4 kreis) */
	    {
	       r_clicked = 0;
	       RS_DIALOGFACTORY->commandMessage("selected arc has AngleLength < 4.66");
	    }
	
	layer_clicked = ae->getLayer();
     }   
   
   for (RS_Entity* en=container->firstEntity(); en!=NULL; en=container->nextEntity()) 
     {
	int included = 0;
	
	if (en!=NULL && en->isVisible() && 
	    en->isAtomic() && en->isSelected()!=select && 
	    (en->rtti()==RS2::EntityArc || en->rtti()==RS2::EntityCircle) &&

	    (en->getLayer()==NULL || en->getLayer()->isLocked()==false)) 
	  {
	     ae = (RS_AtomicEntity*)en;
	     
 
	     if(en->isInWindow(v1, v2))
	       included++;
	     
	     if (cross == true)
	       {
		 RS_Line l[] =
		   {
                        RS_Line(NULL, RS_LineData(v1, RS_Vector(v2.x, v1.y))),
                        RS_Line(NULL, RS_LineData(RS_Vector(v2.x, v1.y), v2)),
                        RS_Line(NULL, RS_LineData(v2, RS_Vector(v1.x, v2.y))),
                        RS_Line(NULL, RS_LineData(RS_Vector(v1.x, v2.y), v1))
		   };
                RS_VectorSolutions sol;

                if (ae->isContainer()) 
		    continue;
                 else
		    {
		       for (int i=0; i<4; ++i) 
			 {
			    sol = RS_Information::getIntersection(ae, &l[i], true);
			    if (sol.hasValid())
			      {
				 included++;
				 break;
			      }
			 }
		    }
	       }
	     
	     // -----------------------
	     
	     if(included)
	       {
		  
		  double rc = ae->getRadius();
		  
		  double rdiff = fabs (rc - r_clicked);
		  
		  if ((r_clicked > 0.000003)  &&  (0.000003 > rdiff) && (ae->getLayer() == layer_clicked))
		    {
		       if (graphicView!=NULL)
			 {
			    graphicView->deleteEntity(ae);
			 }
		       
		       ae->setSelected(select);
		       
		       if (graphicView!=NULL) 
			 {
			    graphicView->drawEntity(ae);
			 }
		    }
	       }
	  }
     }
   //std::cerr << "ende in  rs_selection.cpp \n";
}