/** * Testing function. */ void LC_SimpleTests::slotTestInsertMText() { RS_DEBUG->print("%s\n: begin\n", __func__); RS_Document* d = QC_ApplicationWindow::getAppWindow()->getDocument(); if (d) { RS_Graphic* graphic = (RS_Graphic*)d; if (graphic==NULL) { return; } RS_MText* text; RS_MTextData textData; textData = RS_MTextData(RS_Vector(10.0,10.0), 10.0, 100.0, RS_MTextData::VATop, RS_MTextData::HALeft, RS_MTextData::LeftToRight, RS_MTextData::Exact, 1.0, "LibreCAD", "iso", 0.0); text = new RS_MText(graphic, textData); text->setLayerToActive(); text->setPen(RS_Pen(RS_Color(255, 0, 0), RS2::Width01, RS2::SolidLine)); graphic->addEntity(text); } RS_DEBUG->print("%s\n: end\n", __func__); }
/** * Sets a variable value for the parent graphic object. * * @param key Variable name (e.g. "$DIMASZ") * @param val Default value */ void RS_Entity::addGraphicVariable(const RS_String& key, const RS_String& val, int code) { RS_Graphic* graphic = getGraphic(); if (graphic!=NULL) { graphic->addVariable(key, val, code); } }
/** * Testing function. */ void LC_SimpleTests::slotTestInsertImage() { RS_DEBUG->print("%s\n: begin\n", __func__); RS_Document* d = QC_ApplicationWindow::getAppWindow()->getDocument(); if (d) { RS_Graphic* graphic = (RS_Graphic*)d; if (graphic==NULL) { return; } RS_Image* image; RS_ImageData imageData; imageData = RS_ImageData(0, RS_Vector(50.0,30.0), RS_Vector(0.5,0.5), RS_Vector(-0.5,0.5), RS_Vector(640,480), "/home/andrew/data/image.png", 50, 50, 0); image = new RS_Image(graphic, imageData); image->setLayerToActive(); image->setPen(RS_Pen(RS_Color(255, 0, 0), RS2::Width01, RS2::SolidLine)); graphic->addEntity(image); } RS_DEBUG->print("%s\n: end\n", __func__); }
/** * @return Automatically created label for the default * measurement of this dimension. */ QString RS_DimLinear::getMeasuredLabel() { // direction of dimension line RS_Vector dirDim; dirDim.setPolar(100.0, edata.angle); // construction line for dimension line RS_ConstructionLine dimLine(NULL, RS_ConstructionLineData(data.definitionPoint, data.definitionPoint + dirDim)); RS_Vector dimP1 = dimLine.getNearestPointOnEntity(edata.extensionPoint1); RS_Vector dimP2 = dimLine.getNearestPointOnEntity(edata.extensionPoint2); // Definitive dimension line: double dist = dimP1.distanceTo(dimP2); RS_Graphic* graphic = getGraphic(); QString ret; if (graphic!=NULL) { ret = RS_Units::formatLinear(dist, graphic->getUnit(), graphic->getLinearFormat(), graphic->getLinearPrecision()); } else { ret = QString("%1").arg(dist); } return ret; }
void QG_DlgEllipse::setEllipse(RS_Ellipse& e) { ellipse = &e; //pen = ellipse->getPen(); wPen->setPen(ellipse->getPen(false), true, false, "Pen"); RS_Graphic* graphic = ellipse->getGraphic(); if (graphic!=NULL) { cbLayer->init(*(graphic->getLayerList()), false, false); } RS_Layer* lay = ellipse->getLayer(false); if (lay!=NULL) { cbLayer->setLayer(*lay); } QString s; s.setNum(ellipse->getCenter().x); leCenterX->setText(s); s.setNum(ellipse->getCenter().y); leCenterY->setText(s); s.setNum(ellipse->getMajorP().magnitude()); leMajor->setText(s); s.setNum(ellipse->getMajorP().magnitude()*ellipse->getRatio()); leMinor->setText(s); s.setNum(RS_Math::rad2deg(ellipse->getMajorP().angle())); leRotation->setText(s); s.setNum(RS_Math::rad2deg(ellipse->getAngle1())); leAngle1->setText(s); s.setNum(RS_Math::rad2deg(ellipse->getAngle2())); leAngle2->setText(s); cbReversed->setChecked(ellipse->isReversed()); }
void QG_DlgImage::setImage(RS_Image& e) { image = &e; val = new QDoubleValidator(leScale); //pen = spline->getPen(); wPen->setPen(image->getPen(false), true, false, "Pen"); RS_Graphic* graphic = image->getGraphic(); if (graphic!=NULL) { cbLayer->init(*(graphic->getLayerList()), false, false); } RS_Layer* lay = image->getLayer(false); if (lay!=NULL) { cbLayer->setLayer(*lay); } leInsertX->setValidator(val); leInsertY->setValidator(val); leWidth->setValidator(val); leHeight->setValidator(val); leScale->setValidator(val); leAngle->setValidator(val); scale = image->getUVector().magnitude(); leInsertX->setText(QString("%1").arg(image->getInsertionPoint().x)); leInsertY->setText(QString("%1").arg(image->getInsertionPoint().y)); leWidth->setText(QString("%1").arg(image->getImageWidth())); leHeight->setText(QString("%1").arg(image->getImageHeight())); leScale->setText(QString("%1").arg(scale)); leAngle->setText(QString("%1").arg( RS_Math::rad2deg(image->getUVector().angle()) )); lePath->setText(image->getFile()); leSize->setText(QString("%1 x %2").arg(image->getWidth()).arg(image->getHeight())); leDPI->setText(QString("%1").arg(RS_Units::scaleToDpi(scale,image->getGraphicUnit()))); }
/** * Sets the parent documents modified status to 'm'. */ void RS_Block::setModified(bool m) { RS_Graphic* p = getGraphic(); if (p) { p->setModified(m); } modified = m; }
/** * @return Automatically created label for the default * measurement of this dimension. */ QString RS_DimDiametric::getMeasuredLabel() { // Definitive dimension line: double dist = data.definitionPoint.distanceTo(edata.definitionPoint) * getGeneralFactor(); RS_Graphic* graphic = getGraphic(); QString ret; if (graphic) { int dimlunit = getGraphicVariableInt("$DIMLUNIT", 2); int dimdec = getGraphicVariableInt("$DIMDEC", 4); int dimzin = getGraphicVariableInt("$DIMZIN", 1); RS2::LinearFormat format = graphic->getLinearFormat(dimlunit); ret = RS_Units::formatLinear(dist, RS2::None, format, dimdec); if (format == RS2::Decimal) ret = stripZerosLinear(ret, dimzin); //verify if units are decimal and comma separator if (dimlunit==2){ if (getGraphicVariableInt("$DIMDSEP", 0) == 44) ret.replace(QChar('.'), QChar(',')); } } else { ret = QString("%1").arg(dist); } return ret; }
void QG_DlgInsert::setInsert(RS_Insert& i) { insert = &i; //pen = insert->getPen(); wPen->setPen(insert->getPen(false), true, false, "Pen"); RS_Graphic* graphic = insert->getGraphic(); if (graphic!=NULL) { cbLayer->init(*(graphic->getLayerList()), false, false); } RS_Layer* lay = insert->getLayer(false); if (lay!=NULL) { cbLayer->setLayer(*lay); } QString s; s.setNum(insert->getInsertionPoint().x); leInsertionPointX->setText(s); s.setNum(insert->getInsertionPoint().y); leInsertionPointY->setText(s); s.setNum(insert->getScale().x); leScaleX->setText(s); s.setNum(insert->getScale().y); leScaleY->setText(s); s.setNum(RS_Math::rad2deg(insert->getAngle())); leAngle->setText(s); s.setNum(insert->getRows()); leRows->setText(s); s.setNum(insert->getCols()); leCols->setText(s); s.setNum(insert->getSpacing().x); leRowSpacing->setText(s); s.setNum(insert->getSpacing().y); leColSpacing->setText(s); }
void LC_DlgSplinePoints::setSpline(LC_SplinePoints& b) { bezier = &b; //pen = spline->getPen(); ui->wPen->setPen(b.getPen(false), true, false, "Pen"); RS_Graphic* graphic = b.getGraphic(); if (graphic) { ui->cbLayer->init(*(graphic->getLayerList()), false, false); } RS_Layer* lay = b.getLayer(false); if (lay) { ui->cbLayer->setLayer(*lay); } ui->cbClosed->setChecked(b.isClosed()); //number of control points auto const& bData = b.getData(); auto const n = bData.splinePoints.size(); if (n <= 2) { ui->rbControlPoints->setChecked(true); ui->rbSplinePoints->setEnabled(false); } else ui->rbSplinePoints->setChecked(true); updatePoints(); }
/** * Loads the given pattern file into this pattern. * Entities other than lines are ignored. * * @param filename File name of the pattern file (without path and * extension or full path. */ bool RS_Pattern::loadPattern() { if (loaded) { return true; } RS_DEBUG->print("RS_Pattern::loadPattern"); QString path; // Search for the appropriate pattern if we have only the name of the pattern: if (!fileName.toLower().contains(".dxf")) { QStringList patterns = RS_SYSTEM->getPatternList(); QFileInfo file; for (QStringList::Iterator it = patterns.begin(); it!=patterns.end(); it++) { if (QFileInfo(*it).baseName().toLower()==fileName.toLower()) { path = *it; RS_DEBUG->print("Pattern found: %s", path.toLatin1().data()); break; } } } // We have the full path of the pattern: else { path = fileName; } // No pattern paths found: if (path.isEmpty()) { RS_DEBUG->print("No pattern \"%s\"available.", fileName.toLatin1().data()); return false; } RS_Graphic* gr = new RS_Graphic(); // TODO: Find out why the new dxf filter doesn't work for patterns: RS_FILEIO->fileImport(*gr, path, RS2::FormatDXF1); for (RS_Entity* e=gr->firstEntity(); e!=NULL; e=gr->nextEntity()) { if (e->rtti()==RS2::EntityLine || e->rtti()==RS2::EntityArc) { RS_Layer* l = e->getLayer(); RS_Entity* cl = e->clone(); cl->reparent(this); if (l!=NULL) { cl->setLayer(l->getName()); } addEntity(cl); } } delete gr; loaded = true; RS_DEBUG->print("RS_Pattern::loadPattern: OK"); return true; }
/** * @return The unit the parent graphic works on or None if there's no * parent graphic. */ RS2::Unit RS_Entity::getGraphicUnit() { RS_Graphic* graphic = getGraphic(); RS2::Unit ret = RS2::None; if (graphic!=NULL) { ret = graphic->getUnit(); } return ret; }
/** * Sets the layer of this entity to the layer with the given name */ void RS_Entity::setLayer(const RS_String& name) { RS_Graphic* graphic = getGraphic(); if (graphic!=NULL) { layer = graphic->findLayer(name); } else { layer = NULL; } }
bool RS_Block::saveAs(const QString& filename, RS2::FormatType type, bool force) { RS_Graphic* g = getGraphic(); if (g) { return g->saveAs(filename, type, force); } else { return false; } }
/** * A safe member function to return the given variable. * * @param key Variable name (e.g. "$DIMASZ") * @param def Default value * * @return value of variable or default value if the given variable * doesn't exist. */ int RS_Entity::getGraphicVariableInt(const RS_String& key, int def) { RS_Graphic* graphic = getGraphic(); int ret=def; if (graphic!=NULL) { ret = graphic->getVariableInt(key, def); } return ret; }
/** * A safe member function to return the given variable. * * @param key Variable name (e.g. "$DIMASZ") * @param def Default value * * @return value of variable or default value if the given variable * doesn't exist. */ double RS_Entity::getGraphicVariableDouble(const RS_String& key, double def) { RS_Graphic* graphic = getGraphic(); double ret=def; if (graphic!=NULL) { ret = graphic->getVariableDouble(key, def); } return ret; }
/** * Sets the layer of this entity to the layer with the given name */ void RS_Entity::setLayer(const QString& name) { RS_Graphic* graphic = getGraphic(); if (graphic) { layer = graphic->findLayer(name); } else { layer = nullptr; } }
bool RS_Block::save(bool isAutoSave) { RS_Graphic* g = getGraphic(); if (g) { return g->save(isAutoSave); } else { return false; } }
RS_BlockList* RS_Block::getBlockList() { RS_Graphic* g = getGraphic(); if (g) { return g->getBlockList(); } else { return NULL; } }
RS_LayerList* RS_Block::getLayerList() { RS_Graphic* g = getGraphic(); if (g!=NULL) { return g->getLayerList(); } else { return NULL; } }
/** * Sets the layer of this entity to the current layer of * the graphic this entity is in. If this entity (and none * of its parents) are in a graphic the layer is set to nullptr. */ void RS_Entity::setLayerToActive() { RS_Graphic* graphic = getGraphic(); if (graphic) { layer = graphic->getActiveLayer(); } else { layer = nullptr; } }
/** * @return true if the grid is switched on. */ bool RS_GraphicView::isGridOn() { if (container!=NULL) { RS_Graphic* g = container->getGraphic(); if (g!=NULL) { return g->isGridOn(); } } return true; }
/** * Sets the layer of this entity to the current layer of * the graphic this entity is in. If this entity (and none * of its parents) are in a graphic the layer is set to NULL. */ void RS_Entity::setLayerToActive() { RS_Graphic* graphic = getGraphic(); if (graphic!=NULL) { layer = graphic->getActiveLayer(); } else { layer = NULL; } }
/** * A safe member function to return the given variable. * * @param key Variable name (e.g. "$DIMASZ") * @param def Default value * * @return value of variable or default value if the given variable * doesn't exist. */ RS_String RS_Entity::getGraphicVariableString(const RS_String& key, const RS_String& def) { RS_Graphic* graphic = getGraphic(); RS_String ret=def; if (graphic!=NULL) { ret = graphic->getVariableString(key, def); } return ret; }
/** * @return true if the grid is switched on. */ bool RS_GraphicView::isGridOn() const{ if (container) { RS_Graphic* g = container->getGraphic(); if (g) { return g->isGridOn(); } } return true; }
/** * A safe member function to return the given variable. * * @param key Variable name (e.g. "$DIMASZ") * @param def Default value * * @return value of variable or default value if the given variable * doesn't exist. */ QString RS_Entity::getGraphicVariableString(const QString& key, const QString& def) const { RS_Graphic* graphic = getGraphic(); QString ret=def; if (graphic) { ret = graphic->getVariableString(key, def); } return ret; }
/** * Implementation of the method used for RS_Import to communicate * with this filter. * * @param g The graphic in which the entities from the file * will be created or the graphics from which the entities are * taken to be stored in a file. */ bool RS_FilterLFF::fileImport(RS_Graphic& g, const QString& file, RS2::FormatType /*type*/) { RS_DEBUG->print("LFF Filter: importing file '%s'...", file.toLatin1().data()); //this->graphic = &g; bool success = false; // Load font file as we normally do, but the font doesn't own the // letters (we'll add them to the graphic instead. Hence 'false'). RS_Font font(file, false); success = font.loadFont(); if (success==false) { RS_DEBUG->print(RS_Debug::D_WARNING, "Cannot open LFF file '%s'.", file.toLatin1().data()); return false; } g.addVariable("Names", font.getNames().join(","), 0); g.addVariable("LetterSpacing", font.getLetterSpacing(), 0); g.addVariable("WordSpacing", font.getWordSpacing(), 0); g.addVariable("LineSpacingFactor", font.getLineSpacingFactor(), 0); g.addVariable("Authors", font.getAuthors().join(","), 0); g.addVariable("License", font.getFileLicense(), 0); g.addVariable("Created", font.getFileCreate(), 0); if (!font.getEncoding().isEmpty()) { g.addVariable("Encoding", font.getEncoding(), 0); } font.generateAllFonts(); RS_BlockList* letterList = font.getLetterList(); for (uint i=0; i<font.countLetters(); ++i) { RS_Block* ch = font.letterAt(i); QString uCode; uCode.setNum(ch->getName().at(0).unicode(), 16); while (uCode.length()<4) { // uCode.rightJustified(4, '0'); uCode="0"+uCode; } //ch->setName("[" + uCode + "] " + ch->getName()); //letterList->rename(ch, QString("[%1]").arg(ch->getName())); letterList->rename(ch, QString("[%1] %2").arg(uCode).arg(ch->getName().at(0))); g.addBlock(ch, false); ch->reparent(&g); } g.addBlockNotification(); return true; }
/** * Adds a line to the current graphic document. */ void rsPyAddLine(double x1, double y1, double x2, double y2) { //printf("c: addLine called\n"); //printf("c: parameter from python: %f\n", x1); RS_Graphic* graphic = RS_SIMPLEPYTHON->getGraphic(); if (graphic!=NULL) { graphic->addEntity(new RS_Line(graphic, RS_LineData(RS_Vector(x1, y1), RS_Vector(x2, y2)))); } else { std::cerr << "rsPyAddLine: No graphic object set.\n"; } }
/** * Zooms to page extends. */ void RS_GraphicView::zoomPage() { RS_DEBUG->print("RS_GraphicView::zoomPage"); if (!container) { return; } RS_Graphic* graphic = container->getGraphic(); if (!graphic) { return; } RS_Vector s = graphic->getPaperSize()/graphic->getPaperScale(); double fx, fy; if (s.x>RS_TOLERANCE) { fx = (getWidth()-borderLeft-borderRight) / s.x; } else { fx = 1.0; } if (s.y>RS_TOLERANCE) { fy = (getHeight()-borderTop-borderBottom) / s.y; } else { fy = 1.0; } RS_DEBUG->print("f: %f/%f", fx, fy); fx = fy = std::min(fx, fy); RS_DEBUG->print("f: %f/%f", fx, fy); if (fx<RS_TOLERANCE) { fx=fy=1.0; } setFactorX(fx); setFactorY(fy); RS_DEBUG->print("f: %f/%f", fx, fy); centerOffsetX(); centerOffsetY(); adjustOffsetControls(); adjustZoomControls(); // updateGrid(); redraw(); }
void QG_DlgDimension::setDim(RS_Dimension& d) { dim = &d; wPen->setPen(dim->getPen(false), true, false, "Pen"); RS_Graphic* graphic = dim->getGraphic(); if (graphic!=NULL) { cbLayer->init(*(graphic->getLayerList()), false, false); } RS_Layer* lay = dim->getLayer(false); if (lay!=NULL) { cbLayer->setLayer(*lay); } wLabel->setLabel(dim->getLabel(false)); }