/** * Testing function. */ void LC_SimpleTests::slotTestMath01() { RS_DEBUG->print("%s\n: begin\n", __func__); auto appWin=QC_ApplicationWindow::getAppWindow(); RS_Document* d = appWin->getDocument(); if (d) { RS_Graphic* graphic = (RS_Graphic*)d; if (!graphic) { return; } // axis graphic->addEntity(new RS_Line{graphic, {0.,0.}, {2*M_PI,0.}}); graphic->addEntity(new RS_Line{graphic, {0., -1.}, {0., 1.}}); // cos double a; double x = RS_Math::deg2rad(59.0); double x_0 = RS_Math::deg2rad(60.0); for (a=0.01; a<2*M_PI; a+=0.01) { // cos curve: RS_Line* line = new RS_Line{graphic, {a-0.01, cos(a-0.01)}, {a, cos(a)}}; graphic->addEntity(line); // tangent: graphic->addEntity(new RS_Line{graphic, {a-0.01,cos(x_0)-sin(x_0)*(a-0.01-x_0)}, {a,cos(x_0)-sin(x_0)*(a-x_0)}}); } // 59.0 deg graphic->addEntity(new RS_Line{graphic, {x,0.}, {x,1.}}); // 60.0 deg graphic->addEntity(new RS_Line{graphic, {x_0,0.}, {x_0,1.}}); // tangent //graphic->addEntity(new RS_Line(graphic, // RS_Vector(0.0,cos(x_0)-sin(x_0)*(0.0-x_0)), // RS_Vector(6.0,cos(x_0)-sin(x_0)*(6.0-x_0)))); RS_GraphicView* v = appWin->getGraphicView(); if (v) { v->redraw(); } } RS_DEBUG->print("%s\n: end\n", __func__); }
/** * Called by Qt when the user closes this MDI window. */ void QC_MDIWindow::closeEvent(QCloseEvent* ce) { auto view = getGraphicView(); view->killAllActions(); RS_DEBUG->print("QC_MDIWindow::closeEvent begin"); if (forceClosing) { ce->accept(); return; } if (closeMDI(false)) { ce->accept(); } else { ce->ignore(); } RS_DEBUG->print("QC_MDIWindow::closeEvent end"); }
/** * Testing function. */ void LC_SimpleTests::slotTestInsertEllipse() { RS_DEBUG->print("%s\n: begin\n", __func__); auto appWin=QC_ApplicationWindow::getAppWindow(); RS_Document* d = appWin->getDocument(); if (d) { RS_Graphic* graphic = (RS_Graphic*)d; if (!graphic) { return; } RS_Ellipse* ellipse; RS_Line* line; for (double a=0.; a<2.*M_PI; a+=0.1) { RS_Vector v = RS_Vector::polar(50., a); double xp = 1000.*a; ellipse = new RS_Ellipse(graphic, {xp,0.}, v, 0.5, 0., 2.*M_PI, false); ellipse->setPen(RS_Pen(RS_Color(255, 0, 255), RS2::Width01, RS2::SolidLine)); graphic->addEntity(ellipse); //graphic->addEntity(new RS_Point(graphic, ellipse->getMax())); //graphic->addEntity(new RS_Point(graphic, ellipse->getMin())); line = new RS_Line{graphic, {xp, 0.}, RS_Vector{xp, 0.}+v}; line->setPen(RS_Pen(RS_Color(128, 128, 128), RS2::Width01, RS2::SolidLine)); graphic->addEntity(line); /* for (double mx=-60.0; mx<60.0; mx+=1.0) { //for (double mx=0.0; mx<1.0; mx+=2.5) { RS_VectorSolutions sol = ellipse->mapX(xp + mx); //graphic->addEntity(new RS_Point(graphic, // sol.vector2 + RS_Vector(a*500.0, 0.0))); //graphic->addEntity(new RS_Point(graphic, // sol.vector3 + RS_Vector(a*500.0, 0.0))); //graphic->addEntity(new RS_Point(graphic, // sol.vector4 + RS_Vector(a*500.0, 0.0))); line = new RS_Line(graphic, RS_LineData(RS_Vector(xp+mx,-50.0), RS_Vector(xp+mx,50.0))); line->setPen(RS_Pen(RS_Color(60, 60, 60), RS2::Width01, RS2::SolidLine)); graphic->addEntity(line); graphic->addEntity(new RS_Point(graphic, sol.get(0))); } */ } // different minor/minor relations /* double x, y; for (y=-250.0; y<=250.0; y+=50.0) { for (x=-250.0; x<=250.0; x+=50.0) { RS_Vector v(x, y); ellipse = new RS_Ellipse(graphic, v, RS_Vector((x/5+50.0)/2.0, 0.0), fabs(x/y), 0.0, 2*M_PI, false); ellipse->setPen(RS_Pen(RS_Color(255, 255, 0), RS2::Width01, RS2::DashDotLine)); graphic->addEntity(ellipse); graphic->addEntity(new RS_Point(graphic, ellipse->getMax())); graphic->addEntity(new RS_Point(graphic, ellipse->getMin())); ellipse = new RS_Ellipse(graphic, v + RS_Vector(750.0, 0.0), RS_Vector((x/5+50.0)/2.0, 0.0), fabs(x/y), 2*M_PI, 0.0, true); graphic->addEntity(ellipse); graphic->addEntity(new RS_Point(graphic, ellipse->getMax())); graphic->addEntity(new RS_Point(graphic, ellipse->getMin())); } } */ /* // different rotation angles: double rot; for (rot=0.0; rot<=2*M_PI+0.1; rot+=(M_PI/8)) { ellipse = new RS_Ellipse(graphic, RS_Vector(rot*200, 500.0), RS_Vector(50.0, 0.0).rotate(rot), 0.3, 0.0, 2*M_PI, false); graphic->addEntity(ellipse); graphic->addEntity(new RS_Point(graphic, ellipse->getMax())); graphic->addEntity(new RS_Point(graphic, ellipse->getMin())); } // different arc angles: double a1, a2; for (rot=0.0; rot<=2*M_PI+0.1; rot+=(M_PI/8)) { for (a1=0.0; a1<=2*M_PI+0.1; a1+=(M_PI/8)) { for (a2=a1+M_PI/8; a2<=2*M_PI+a1+0.1; a2+=(M_PI/8)) { ellipse = new RS_Ellipse(graphic, RS_Vector(-500.0-a1*200.0-5000.0*rot, 500.0-a2*200.0), RS_Vector(50.0, 0.0).rotate(rot), 0.3, a1, a2, false); graphic->addEntity(ellipse); graphic->addEntity(new RS_Point(graphic, ellipse->getMax())); graphic->addEntity(new RS_Point(graphic, ellipse->getMin())); } } } */ RS_GraphicView* v = appWin->getGraphicView(); if (v) { v->redraw(); } } RS_DEBUG->print("%s\n: end\n", __func__); }
/** * Testing function. */ void LC_SimpleTests::slotTestInsertBlock() { RS_DEBUG->print("%s\n: begin\n", __func__); auto appWin=QC_ApplicationWindow::getAppWindow(); RS_Document* d = appWin->getDocument(); if (d && d->rtti()==RS2::EntityGraphic) { RS_Graphic* graphic = (RS_Graphic*)d; if (graphic==NULL) { return; } graphic->addLayer(new RS_Layer("default")); RS_Block* block = new RS_Block(graphic, RS_BlockData("debugblock", RS_Vector(0.0,0.0), true)); RS_Line* line; RS_Arc* arc; RS_Circle* circle; // Add one red line: line = new RS_Line{block, {0.,0.}, {50.,0.}}; line->setLayerToActive(); line->setPen(RS_Pen(RS_Color(255, 0, 0), RS2::Width01, RS2::SolidLine)); block->addEntity(line); // Add one line with attributes from block: line = new RS_Line{block, {50.,0.}, {50.,50.}}; line->setPen(RS_Pen(RS_Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock)); block->addEntity(line); // Add one arc with attributes from block: RS_ArcData d({50.,0.}, 50.0, M_PI_2, M_PI, false); arc = new RS_Arc(block, d); arc->setPen(RS_Pen(RS_Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock)); block->addEntity(arc); // Add one blue circle: RS_CircleData circleData(RS_Vector(20.0,15.0), 12.5); circle = new RS_Circle(block, circleData); circle->setLayerToActive(); circle->setPen(RS_Pen(RS_Color(0, 0, 255), RS2::Width01, RS2::SolidLine)); block->addEntity(circle); graphic->addBlock(block); RS_Insert* ins; RS_InsertData insData("debugblock", RS_Vector(0.0,0.0), RS_Vector(1.0,1.0), 0.0, 1, 1, RS_Vector(0.0, 0.0), NULL, RS2::NoUpdate); // insert one magenta instance of the block (original): ins = new RS_Insert(graphic, insData); ins->setLayerToActive(); ins->setPen(RS_Pen(RS_Color(255, 0, 255), RS2::Width02, RS2::SolidLine)); ins->update(); graphic->addEntity(ins); // insert one green instance of the block (rotate): insData = RS_InsertData("debugblock", RS_Vector(-50.0,20.0), RS_Vector(1.0,1.0), M_PI/6., 1, 1, RS_Vector(0.0, 0.0), NULL, RS2::NoUpdate); ins = new RS_Insert(graphic, insData); ins->setLayerToActive(); ins->setPen(RS_Pen(RS_Color(0, 255, 0), RS2::Width02, RS2::SolidLine)); ins->update(); graphic->addEntity(ins); // insert one cyan instance of the block (move): insData = RS_InsertData("debugblock", RS_Vector(10.0,20.0), RS_Vector(1.0,1.0), 0.0, 1, 1, RS_Vector(0.0, 0.0), NULL, RS2::NoUpdate); ins = new RS_Insert(graphic, insData); ins->setLayerToActive(); ins->setPen(RS_Pen(RS_Color(0, 255, 255), RS2::Width02, RS2::SolidLine)); ins->update(); graphic->addEntity(ins); // insert one blue instance of the block: for (double a=0.0; a<360.0; a+=45.0) { insData = RS_InsertData("debugblock", RS_Vector(60.0,0.0), RS_Vector(2.0/5,2.0/5), RS_Math::deg2rad(a), 1, 1, RS_Vector(0.0, 0.0), NULL, RS2::NoUpdate); ins = new RS_Insert(graphic, insData); ins->setLayerToActive(); ins->setPen(RS_Pen(RS_Color(0, 0, 255), RS2::Width05, RS2::SolidLine)); ins->update(); graphic->addEntity(ins); } // insert an array of yellow instances of the block: insData = RS_InsertData("debugblock", RS_Vector(-100.0,-100.0), RS_Vector(0.2,0.2), M_PI/6.0, 6, 4, RS_Vector(100.0, 100.0), NULL, RS2::NoUpdate); ins = new RS_Insert(graphic, insData); ins->setLayerToActive(); ins->setPen(RS_Pen(RS_Color(255, 255, 0), RS2::Width01, RS2::SolidLine)); ins->update(); graphic->addEntity(ins); RS_GraphicView* v = appWin->getGraphicView(); if (v) { v->redraw(); } } RS_DEBUG->print("%s\n: end\n", __func__); }