void RS_ActionDrawNephroid::trigger() {
    if (pt.valid) {


        RS_Point* point = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point);
        float a=pt.x;
        float b=pt.y;
        float radius=10;

        for (float angle = 0;  angle <= 200; angle += 1)
        {
            pt.x = pt.x + (radius * (3.0 * cos(angle) - cos(3.0*angle))+.5);
            pt.y = pt.y + (radius * (3.0 * sin(angle) - sin(3.0*angle))+.5);

            RS_Point* point1 = new RS_Point(container, RS_PointData(pt));
            container->addEntity(point1);
            pt.x =a;
            pt.y=b;


        }



        if (document) {
            document->startUndoCycle();
            document->addUndoable(point);
            document->endUndoCycle();
        }

        graphicView->redraw(RS2::RedrawDrawing);
        graphicView->moveRelativeZero(pt);
    }
}
void LC_ActionDrawCircle2PR::mouseMoveEvent(QMouseEvent* e) {
	RS_Vector mouse = snapPoint(e);

	switch (getStatus()) {
	case SetPoint1:
		pPoints->point1 = mouse;
		break;

	case SetPoint2:
		if(mouse.distanceTo(pPoints->point1) <= 2.*data->radius) pPoints->point2 = mouse;
		break;

	case SelectCenter: {
		if(preparePreview(mouse)){
			bool existing=false;
			for(auto p: *preview){
				if(p->rtti() == RS2::EntityCircle){
					if( static_cast<RS_Circle*>(p)->getData() == *data)
						existing=true;
				}
			}
			if(!existing){
				deletePreview();
				preview->addEntity(new RS_Point(preview.get(), RS_PointData(data->center)));
				RS_Circle* circle = new RS_Circle(preview.get(), *data);
				preview->addEntity(circle);
				drawPreview();
			}
		}else{
			if(data->isValid()) trigger();
		}
	}
	}
}
void LC_ActionDrawSplinePoints::coordinateEvent(RS_CoordinateEvent* e)
{
	if(e == NULL) return;

	RS_Vector mouse = e->getCoordinate();

	switch (getStatus())
	{
	case SetStartPoint:
		undoBuffer.clear();
		if(spline == NULL)
		{
            spline = new LC_SplinePoints(container, data);
			spline->addPoint(mouse);
			preview->addEntity(new RS_Point(preview, RS_PointData(mouse)));
		}
		setStatus(SetNextPoint);
		graphicView->moveRelativeZero(mouse);
		updateMouseButtonHints();
		break;
	case SetNextPoint:
		graphicView->moveRelativeZero(mouse);
		if(spline != NULL)
		{
			spline->addPoint(mouse);
			drawPreview();
			drawSnapper();
		}
		updateMouseButtonHints();
		break;
	default:
		break;
	}
}
bool RS_ActionDrawCircleTan3::preparePreview(){
	if(getStatus() != SetCenter || valid==false) {
		valid=false;
		return false;
	}
	//find the nearest circle
	size_t index=candidates.size();
	double dist=RS_MAXDOUBLE*RS_MAXDOUBLE;
	for(size_t i=0;i<candidates.size();++i){

		preview->addEntity(new RS_Point(preview.get(), RS_PointData(candidates.at(i)->center)));
		double d;
		RS_Circle(nullptr, *candidates.at(i)).getNearestPointOnEntity(coord,false,&d);
		double dCenter=coord.distanceTo(candidates.at(i)->center);
		d=std::min(d,dCenter);
		if(d<dist){
			dist=d;
			index=i;
		}
	}
	if( index<candidates.size()){
		cData=candidates.at(index);
		valid=true;
	}else{
		valid=false;
	}
	return valid;
}
void Doc_plugin_interface::addPoint(QPointF *start){

    RS_Vector v1(start->x(), start->y());
    if (doc==NULL) {
        RS_DEBUG->print("Doc_plugin_interface::addLine: currentContainer is NULL");
    }

    RS_Point* entity = new RS_Point(doc, RS_PointData(v1));
//    setEntityAttributes(entity, attributes);
    doc->addEntity(entity);
}
void Doc_plugin_interface::addPoint(QPointF *start){

    RS_Vector v1(start->x(), start->y());
    if (doc!=NULL) {
        RS_Point* entity = new RS_Point(doc, RS_PointData(v1));
        doc->addEntity(entity);
        if (!haveUndo) {
            doc->startUndoCycle();
            haveUndo = true;
        }
        doc->addUndoable(entity);
    } else
        RS_DEBUG->print("Doc_plugin_interface::addPoint: currentContainer is NULL");
}
void RS_ActionDrawEpicycloid::trigger() {
    if (pt.valid) {


        RS_Point* point = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point);
       float a=pt.x;
        float b=pt.y;
                float radius2=5,radius1=4*radius2;

        for (float angle = 0;  angle <= 200; angle += 1)
                       {

            pt.x = pt.x +  (radius1 + radius2)*cos(angle) - radius2*cos((radius1/radius2 + 1.0)*angle) +.5;
                   pt.y = pt.y +  (radius1 + radius2)*sin(angle) - radius2*sin((radius1/radius2 + 1.0)*angle)+.5;


                        RS_Point* point1 = new RS_Point(container, RS_PointData(pt));
                   container->addEntity(point1);
                   pt.x =a;
                   pt.y=b;


                }



        if (document) {
            document->startUndoCycle();
            document->addUndoable(point);
            document->endUndoCycle();
        }

                graphicView->redraw(RS2::RedrawDrawing);
        graphicView->moveRelativeZero(pt);
    }
}
void RS_ActionDrawPoint::trigger() {
    if (pt.valid) {
        RS_Point* point = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point);

        if (document) {
            document->startUndoCycle();
            document->addUndoable(point);
            document->endUndoCycle();
        }

                graphicView->redraw(RS2::RedrawDrawing);
        graphicView->moveRelativeZero(pt);
    }
}
Beispiel #9
0
void RS_ActionDrawPoint::trigger() {
    if (pt.valid) {
        RS_Point* point = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point);

        if (document) {
            document->startUndoCycle();
            document->addUndoable(point);
            document->endUndoCycle();
        }

        deleteSnapper();
        graphicView->moveRelativeZero(RS_Vector(0.0,0.0));
        graphicView->drawEntity(point);
        graphicView->moveRelativeZero(pt);
        drawSnapper();
    }
}
void RS_ActionDrawSpline::mouseMoveEvent(QMouseEvent* e) {
    RS_DEBUG->print("RS_ActionDrawSpline::mouseMoveEvent begin");

    RS_Vector mouse = snapPoint(e);
    if (getStatus()==SetNextPoint && spline!=NULL /*&& point.valid*/) {
        deletePreview();

                RS_Spline* tmpSpline = (RS_Spline*)spline->clone();
                tmpSpline->addControlPoint(mouse);
                tmpSpline->update();
                preview->addEntity(tmpSpline);

                QList<RS_Vector> cpts = tmpSpline->getControlPoints();
                for (int i = 0; i < cpts.size(); ++i) {
                        preview->addEntity(new RS_Point(preview, RS_PointData(cpts.at(i))));
                }
        drawPreview();
    }

    RS_DEBUG->print("RS_ActionDrawSpline::mouseMoveEvent end");
}
void RS_ActionDrawSpline::mouseMoveEvent(QMouseEvent* e) {
    RS_DEBUG->print("RS_ActionDrawSpline::mouseMoveEvent begin");

    RS_Vector mouse = snapPoint(e);
	if (getStatus()==SetNextPoint && spline /*&& point.valid*/) {
        deletePreview();

				RS_Spline* tmpSpline = static_cast<RS_Spline*>(spline->clone());
                tmpSpline->addControlPoint(mouse);
                tmpSpline->update();
                preview->addEntity(tmpSpline);

				QList<RS_Vector>&& cpts = tmpSpline->getControlPoints();
				for (const RS_Vector& vp: cpts) {
						preview->addEntity(new RS_Point(preview.get(), RS_PointData(vp)));
                }
        drawPreview();
    }

    RS_DEBUG->print("RS_ActionDrawSpline::mouseMoveEvent end");
}
void RS_ActionDrawCircleTan2::mouseMoveEvent(QMouseEvent* e) {
    RS_DEBUG->print("RS_ActionDrawCircleTan2::mouseMoveEvent begin");

    switch(getStatus() ){
    case SetCenter: {
        //        RS_Entity*  en = catchEntity(e, enTypeList, RS2::ResolveAll);
        coord= graphicView->toGraph(e->x(), e->y());
        //        circles[getStatus()]=static_cast<RS_Line*>(en);
        if(preparePreview()) {
            deletePreview();
			RS_Circle* e=new RS_Circle(preview.get(), *cData);
            preview->addEntity(e);
			for(size_t i=0; i< centers.size(); ++i){
				preview->addEntity(new RS_Point(preview.get(), RS_PointData(centers.at(i))));
			}
            drawPreview();
        }
    }
        break;
    default:
        break;
    }
    RS_DEBUG->print("RS_ActionDrawCircleTan2::mouseMoveEvent end");
}
void LC_ActionDrawSplinePoints::mouseMoveEvent(QMouseEvent* e)
{
	RS_DEBUG->print("RS_ActionDrawSplinePoints::mouseMoveEvent begin");

	RS_Vector mouse = snapPoint(e);
	LC_SplinePoints *sp;

	if(getStatus() == SetNextPoint)
	{
		sp = (LC_SplinePoints*)spline->clone();
		sp->addPoint(mouse);
		deletePreview();
		preview->addEntity(sp);

		QList<RS_Vector> cpts = sp->getPoints();
		for(int i = 0; i < cpts.count(); i++)
		{
			preview->addEntity(new RS_Point(preview, RS_PointData(cpts.at(i))));
		}
		drawPreview();
	}

	RS_DEBUG->print("RS_ActionDrawSplinePoints::mouseMoveEvent end");
}
void RS_ActionDrawCircleTan1_2P::mouseMoveEvent(QMouseEvent* e) {
    RS_DEBUG->print("RS_ActionDrawCircleTan1_2P::mouseMoveEvent begin");

    switch(getStatus() ){
    case SetPoint1:
    {
        RS_Vector&& mouse=snapPoint(e);
		pPoints->points.clear();
		pPoints->points.push_back(mouse);
        switch(circle->rtti()){
        case RS2::EntityArc:
        case RS2::EntityCircle:
        {
			RS_Vector const& dvp=mouse - circle->getCenter();
			double rvp=dvp.magnitude();
            if(rvp<RS_TOLERANCE2) break;
			pPoints->cData.radius=(circle->getRadius()+rvp)*0.5;
			pPoints->cData.center=circle->getCenter()+dvp*(pPoints->cData.radius/rvp);
			pPoints->cData.radius=fabs(circle->getRadius()-pPoints->cData.radius);
        }
            break;
        case RS2::EntityLine:
        {
            RS_Line* line=static_cast<RS_Line*>(circle);
			RS_Vector&& vp=line->getNearestPointOnEntity(pPoints->points[0],false);
            if(vp.valid){
				pPoints->cData.center=(vp+pPoints->points[0])*0.5;
				pPoints->cData.radius=vp.distanceTo(pPoints->cData.center);
            }
        }
            break;
        default:
            return;
        }
        deletePreview();
		RS_Circle* e=new RS_Circle(preview.get(), pPoints->cData);
        preview->addEntity(e);
        drawPreview();
        break;
    }
    case SetPoint2: {
		RS_Vector const& mouse=snapPoint(e);
		pPoints->points.resize(1);
		pPoints->points.push_back(mouse);
        deletePreview();
		pPoints->coord=mouse;
		if (!getCenters()) return;
		if (preparePreview()) {
			RS_Circle* e=new RS_Circle(preview.get(), pPoints->cData);
            preview->addEntity(e);
            drawPreview();
        }
        break;
    }
    case SetCenter: {

        //        RS_Entity*  en = catchEntity(e, enTypeList, RS2::ResolveAll);
		pPoints->coord= graphicView->toGraph(e->x(), e->y());
        //        circles[getStatus()]=static_cast<RS_Line*>(en);
        if(preparePreview()) {
            deletePreview();
			RS_Circle* e=new RS_Circle(preview.get(), pPoints->cData);
			for(size_t i=0; i<pPoints->centers.size(); ++i)
				preview->addEntity(new RS_Point(preview.get(), RS_PointData(pPoints->centers.at(i))));
            preview->addEntity(e);
//            double r0=cData.radius*0.1;
//            if(centers.size()>1)
//                for(unsigned i=0; i< centers.size(); ++i){
//                    RS_DEBUG->print(RS_Debug::D_ERROR, "center %d: (%g, %g)\n",i,centers.at(i).x,centers.at(i).y);
//                    preview->addEntity(new RS_Circle(preview, RS_CircleData(centers.at(i), r0)));
//                }
            drawPreview();
        }
    }
        break;
    default:
        break;
    }
    RS_DEBUG->print("RS_ActionDrawCircleTan1_2P::mouseMoveEvent end");
}
/*RS_EntityContainer* parent,
                 const RS_LineData& d*/
Plugin_Entity::Plugin_Entity(RS_EntityContainer* parent, enum DPI::ETYPE type){
    hasContainer = false;
    entity = NULL;
    switch (type) {
    case DPI::POINT:
        entity = new RS_Point(parent, RS_PointData(RS_Vector(0,0)));
        break;
    case DPI::LINE:
        entity = new RS_Line(parent, RS_LineData());
        break;
/*    case DPI::CONSTRUCTIONLINE:
        entity = new RS_ConstructionLine();
        break;*/
    case DPI::CIRCLE:
        entity = new RS_Circle(parent, RS_CircleData());
        break;
    case DPI::ARC:
        entity = new RS_Arc(parent, RS_ArcData());
        break;
    case DPI::ELLIPSE:
        entity = new RS_Ellipse(parent, RS_EllipseData(RS_Vector(0,0), RS_Vector(0,0),0.0,0.0,0.0,false));
        break;
    case DPI::IMAGE:
        entity = new RS_Image(parent, RS_ImageData());
        break;
/*    case DPI::OVERLAYBOX:
        entity = new RS_OverlayBox();
        break;
    case DPI::SOLID:
        entity = new RS_Solid();
        break;*/
    case DPI::TEXT:
        entity = new RS_Text(parent, RS_TextData());
        break;
/*    case DPI::INSERT:
        entity = new RS_Insert();
        break;*/
    case DPI::POLYLINE:
        entity = new RS_Polyline(parent, RS_PolylineData());
        break;
/*    case DPI::SPLINE:
        entity = new RS_Spline();
        break;
    case DPI::HATCH:
        entity = new RS_Hatch();
        break;
    case DPI::DIMLEADER:
        entity = new RS_Leader();
        break;
    case DPI::DIMALIGNED:
        entity = new RS_DimAligned();
        break;
    case DPI::DIMLINEAR:
        entity = new RS_DimLinear();
        break;
    case DPI::DIMRADIAL:
        entity = new RS_DimRadial();
        break;
    case DPI::DIMDIAMETRIC:
        entity = new RS_DimDiametric();
        break;
    case DPI::DIMANGULAR:
        entity = new RS_DimAngular();
        break;*/
    default:
        break;
    }
}
void RS_ActionDrawStar::trigger() {
    if (pt.valid) {
        RS_Point* point = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point);


      {int i,j,k,l,m,n,p,q;       //star
        for(i=0;i<10;i++)
       {

           pt.x=i+pt.x;
           pt.y=i+pt.y;

        RS_Point* point1 = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point1);}

        for(i=0;i<10;i++)
       { pt.x=pt.x-i;
         pt.y=pt.y-i;}

      for(m=0;m<10;m++)
       {

           pt.x=m+pt.x;

        RS_Point* point1 = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point1);}

        for(m=0;m<10;m++)
       { pt.x=pt.x-m;
        }
        

        for(n=0;n<10;n++)
       {

           pt.x=pt.x-n;

        RS_Point* point1 = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point1);}

        for(n=0;n<10;n++)
       { pt.x=pt.x+n;
        } 

       
      for(p=0;p<10;p++)
       {

           pt.y=pt.y+p;

        RS_Point* point1 = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point1);}

        for(p=0;p<10;p++)
       { pt.y=pt.y-p;
        }

       for(q=0;q<10;q++)
       {

           pt.y=pt.y-q;

        RS_Point* point1 = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point1);}

        for(q=0;q<10;q++)
       { pt.y=pt.y+q;
        }


        for(j=0;j<10;j++)
       {
         pt.x=pt.x-j;
         pt.y=pt.y-j;

        RS_Point* point3 = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point3);}

        for(j=0;j<10;j++)
       {
         pt.x=pt.x+j;
         pt.y=pt.y+j;}

        for(k=0;k<10;k++)
       {
         pt.x=pt.x-k;
         pt.y=pt.y+k;

        RS_Point* point4 = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point4);}

        for(k=0;k<10;k++)
       {
         pt.x=pt.x+k;
         pt.y=pt.y-k;}


        for(l=0;l<10;l++)
       {
         pt.x=pt.x+l;
         pt.y=pt.y-l;

        RS_Point* point5 = new RS_Point(container, RS_PointData(pt));
        container->addEntity(point5);}

        for(l=0;l<10;l++)
       {
         pt.x=pt.x-l;
         pt.y=pt.y+l;}


        }






        if (document) {
            document->startUndoCycle();
            document->addUndoable(point);
            document->endUndoCycle();
        }

                graphicView->redraw(RS2::RedrawDrawing);
        graphicView->moveRelativeZero(pt);
    }
}