/** * @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; }
/** * @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; }
/** * @return Automatically creted label for the default * measurement of this dimension. */ QString RS_DimAligned::getMeasuredLabel() { double dist = edata.extensionPoint1.distanceTo(edata.extensionPoint2); 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; }
/** * @return Automatically created label for the default * measurement of this dimension. */ QString RS_DimRadial::getMeasuredLabel() { // Definitive dimension line: double dist = data.definitionPoint.distanceTo(edata.definitionPoint) * getGeneralFactor(); 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; }
/** * @return Factor for scaling the line styles considering the current * paper scaling and the fact that styles are stored in Millimeter. */ double RS_Entity::getStyleFactor(RS_GraphicView* view) { double styleFactor = 1.0; if (view!=NULL) { if (view->isPrinting()==false && view->isDraftMode()) { styleFactor = 1.0/view->getFactor().x; } else { //styleFactor = getStyleFactor(); // the factor caused by the unit: RS2::Unit unit = RS2::None; RS_Graphic* g = getGraphic(); if (g!=NULL) { unit = g->getUnit(); //double scale = g->getPaperScale(); styleFactor = RS_Units::convert(1.0, RS2::Millimeter, unit); // / scale; } // the factor caused by the line width: if (((int)getPen(true).getWidth())>0) { styleFactor *= ((double)getPen(true).getWidth()/100.0); } else if (((int)getPen(true).getWidth())==0) { styleFactor *= 0.01; } } if (view->isPrinting() || view->isPrintPreview() || view->isDraftMode()==false) { RS_Graphic* graphic = getGraphic(); if (graphic!=NULL && graphic->getPaperScale()>1.0e-6) { styleFactor /= graphic->getPaperScale(); } } } //RS_DEBUG->print("stylefactor: %f", styleFactor); //RS_DEBUG->print("viewfactor: %f", view->getFactor().x); if (styleFactor*view->getFactor().x<0.2) { styleFactor = -1.0; } return styleFactor; }
/** * Inserts a library item from the given path into the drawing. */ RS_Insert* RS_Creation::createLibraryInsert(RS_LibraryInsertData& data) { RS_DEBUG->print("RS_Creation::createLibraryInsert"); RS_Graphic g; if (!g.open(data.file, RS2::FormatUnknown)) { RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Creation::createLibraryInsert: Cannot open file: %s"); return nullptr; } // unit conversion: if (graphic) { double uf = RS_Units::convert(1.0, g.getUnit(), graphic->getUnit()); g.scale(RS_Vector(0.0, 0.0), RS_Vector(uf, uf)); } //g.scale(RS_Vector(data.factor, data.factor)); //g.rotate(data.angle); QString s; s = QFileInfo(data.file).completeBaseName(); RS_Modification m(*container, graphicView); m.paste( RS_PasteData( data.insertionPoint, data.factor, data.angle, true, s), &g); RS_DEBUG->print("RS_Creation::createLibraryInsert: OK"); return nullptr; }
void RS_GraphicView::setPenForEntity(RS_Painter *painter,RS_Entity *e) { if (draftMode) { painter->setPen(RS_Pen(foreground, RS2::Width00, RS2::SolidLine)); } // Getting pen from entity (or layer) RS_Pen pen = e->getPen(true); int w = pen.getWidth(); if (w<0) { w = 0; } #if 1 /*TRUE*/ // - Scale pen width. // - Notes: pen width is not scaled on print and print preview. // This is the standard (AutoCAD like) behaviour. // bug# 3437941 // ------------------------------------------------------------ if (!draftMode) { double uf = 1.0; // Unit factor. double wf = 1.0; // Width factor. RS_Graphic* graphic = container->getGraphic(); if (graphic) { uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit()); if ( (isPrinting() || isPrintPreview()) && graphic->getPaperScale() > RS_TOLERANCE ) { wf = 1.0 / graphic->getPaperScale(); } } pen.setScreenWidth(toGuiDX(w / 100.0 * uf * wf)); } else { // pen.setWidth(RS2::Width00); pen.setScreenWidth(0); } #else // - Scale pen width. // - Notes: pen width is scaled on print and print preview. // This is not the standard (AutoCAD like) behaviour. // -------------------------------------------------------- if (!draftMode) { double uf = 1.0; // Unit factor. RS_Graphic* graphic = container->getGraphic(); if (graphic) uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit()); pen.setScreenWidth(toGuiDX(w / 100.0 * uf)); } else pen.setScreenWidth(0); #endif // prevent drawing with 1-width which is slow: if (RS_Math::round(pen.getScreenWidth())==1) { pen.setScreenWidth(0.0); } // prevent background color on background drawing: if (pen.getColor().stripFlags()==background.stripFlags()) { pen.setColor(foreground); } // this entity is selected: if (e->isSelected()) { pen.setLineType(RS2::DotLine); pen.setColor(selectedColor); } // this entity is highlighted: if (e->isHighlighted()) { pen.setColor(highlightedColor); } // deleting not drawing: if (getDeleteMode()) { pen.setColor(background); } painter->setPen(pen); }
/** * Updates the grid point array. */ void RS_Grid::updatePointArray() { if (!graphicView->isGridOn()) return; RS_Graphic* graphic = graphicView->getGraphic(); // auto scale grid? RS_SETTINGS->beginGroup("/Appearance"); bool scaleGrid = (bool)RS_SETTINGS->readNumEntry("/ScaleGrid", 1); // get grid setting RS_Vector userGrid; if (graphic) { //$ISOMETRICGRID == $SNAPSTYLE isometric = static_cast<bool>(graphic->getVariableInt("$SNAPSTYLE",0)); crosshairType=graphic->getCrosshairType(); userGrid = graphic->getVariableVector("$GRIDUNIT", RS_Vector(-1.0, -1.0)); }else { isometric = (bool)RS_SETTINGS->readNumEntry("/IsometricGrid", 0); crosshairType=static_cast<RS2::CrosshairType>(RS_SETTINGS->readNumEntry("/CrosshairType",0)); userGrid.x = RS_SETTINGS->readEntry("/GridSpacingX",QString("-1")).toDouble(); userGrid.y = RS_SETTINGS->readEntry("/GridSpacingY",QString("-1")).toDouble(); } int minGridSpacing = RS_SETTINGS->readNumEntry("/MinGridSpacing", 10); RS_SETTINGS->endGroup(); // std::cout<<"Grid userGrid="<<userGrid<<std::endl; pt.clear(); metaX.clear(); metaY.clear(); // RS_DEBUG->print("RS_Grid::update: 001"); // find out unit: RS2::Unit unit = RS2::None; RS2::LinearFormat format = RS2::Decimal; if (graphic) { unit = graphic->getUnit(); format = graphic->getLinearFormat(); } RS_Vector gridWidth; // RS_Vector metaGridWidth; // RS_DEBUG->print("RS_Grid::update: 002"); // init grid spacing: // metric grid: if (RS_Units::isMetric(unit) || unit==RS2::None || format==RS2::Decimal || format==RS2::Engineering) { //metric grid gridWidth = getMetricGridWidth(userGrid, scaleGrid, minGridSpacing); }else { // imperial grid: gridWidth = getImperialGridWidth(userGrid, scaleGrid, minGridSpacing); } // RS_DEBUG->print("RS_Grid::update: 013"); // for grid info: spacing = gridWidth.x; metaSpacing = metaGridWidth.x; //std::cout<<"Grid spacing="<<spacing<<std::endl; //std::cout<<"Grid metaSpacing="<<metaSpacing<<std::endl; if (gridWidth.x>minimumGridWidth && gridWidth.y>minimumGridWidth && graphicView->toGuiDX(gridWidth.x)>2 && graphicView->toGuiDY(gridWidth.y)>2) { // find grid boundaries double left = (int)(graphicView->toGraphX(0) / gridWidth.x) * gridWidth.x; double right = (int)(graphicView->toGraphX(graphicView->getWidth()) / gridWidth.x) * gridWidth.x; double top = (int)(graphicView->toGraphY(0) / gridWidth.y) * gridWidth.y; double bottom = (int)(graphicView->toGraphY(graphicView->getHeight()) / gridWidth.y) * gridWidth.y; left -= gridWidth.x; right += gridWidth.x; top += gridWidth.y; bottom -= gridWidth.y; //top/bottom is reversed with RectF definition LC_Rect const rect{{left, bottom}, {right, top}}; // populate grid points and metaGrid line positions: pts, metaX, metaY if(isometric){ createIsometricGrid(rect, gridWidth); }else{ createOrthogonalGrid(rect, gridWidth); } // RS_DEBUG->print("RS_Grid::update: 015"); } // RS_DEBUG->print("RS_Grid::update: OK"); }
RS_Vector RS_Grid::getImperialGridWidth(RS_Vector const& userGrid, bool scaleGrid, int minGridSpacing) { RS_Vector gridWidth; // RS_DEBUG->print("RS_Grid::update: 005"); if (userGrid.x>0.0) { gridWidth.x = userGrid.x; } else { gridWidth.x = 1.0/1024.0; } if (userGrid.y>0.0) { gridWidth.y = userGrid.y; } else { gridWidth.y = 1.0/1024.0; } // RS_DEBUG->print("RS_Grid::update: 006"); RS2::Unit unit = RS2::None; // RS2::LinearFormat format = RS2::Decimal; RS_Graphic* graphic = graphicView->getGraphic(); if (graphic) { unit = graphic->getUnit(); // format = graphic->getLinearFormat(); } if (unit==RS2::Inch) { // RS_DEBUG->print("RS_Grid::update: 007"); // auto scale grid //scale grid by drawing setting as well, bug#3416862 if (scaleGrid|| userGrid.x<=minimumGridWidth || userGrid.y<=minimumGridWidth) { if(scaleGrid || userGrid.x<=minimumGridWidth) { while (graphicView->toGuiDX(gridWidth.x)<minGridSpacing) { if (RS_Math::round(gridWidth.x)>=36) { gridWidth.x*=2; } else if (RS_Math::round(gridWidth.x)>=12) { gridWidth.x*=3; } else if (RS_Math::round(gridWidth.x)>=4) { gridWidth.x*=3; } else if (RS_Math::round(gridWidth.x)>=1) { gridWidth.x*=2; } else { gridWidth.x*=2; } } } if(scaleGrid || userGrid.y<=minimumGridWidth) { while (graphicView->toGuiDY(gridWidth.y)<minGridSpacing) { if (RS_Math::round(gridWidth.y)>=36) { gridWidth.y*=2; } else if (RS_Math::round(gridWidth.y)>=12) { gridWidth.y*=3; } else if (RS_Math::round(gridWidth.y)>=4) { gridWidth.y*=3; } else if (RS_Math::round(gridWidth.y)>=1) { gridWidth.y*=2; } else { gridWidth.y*=2; } } } } // RS_DEBUG->print("RS_Grid::update: 008"); // metagrid X shows inches.. metaGridWidth.x = 1.0; if (graphicView->toGuiDX(metaGridWidth.x)<minGridSpacing*2) { // .. or feet metaGridWidth.x = 12.0; // .. or yards if (graphicView->toGuiDX(metaGridWidth.x)<minGridSpacing*2) { metaGridWidth.x = 36.0; // .. or miles (not really..) //if (graphicView->toGuiDX(metaGridWidth.x)<20) { // metaGridWidth.x = 63360.0; //} // .. or nothing if (graphicView->toGuiDX(metaGridWidth.x)<minGridSpacing*2) { metaGridWidth.x = -1.0; } } } // RS_DEBUG->print("RS_Grid::update: 009"); // metagrid Y shows inches.. metaGridWidth.y = 1.0; if (graphicView->toGuiDY(metaGridWidth.y)<minGridSpacing*2) { // .. or feet metaGridWidth.y = 12.0; // .. or yards if (graphicView->toGuiDY(metaGridWidth.y)<minGridSpacing*2) { metaGridWidth.y = 36.0; // .. or miles (not really..) //if (graphicView->toGuiDY(metaGridWidth.y)<20) { // metaGridWidth.y = 63360.0; //} // .. or nothing if (graphicView->toGuiDY(metaGridWidth.y)<minGridSpacing*2) { metaGridWidth.y = -1.0; } } } // RS_DEBUG->print("RS_Grid::update: 010"); } else { // RS_DEBUG->print("RS_Grid::update: 011"); if (scaleGrid) { while (graphicView->toGuiDX(gridWidth.x)<minGridSpacing) { gridWidth.x*=2; } metaGridWidth.x = -1.0; while (graphicView->toGuiDY(gridWidth.y)<minGridSpacing) { gridWidth.y*=2; } metaGridWidth.y = -1.0; } // RS_DEBUG->print("RS_Grid::update: 012"); } //gridWidth.y = gridWidth.x; //metaGridWidth.y = metaGridWidth.x; return gridWidth; }
/** * Updates the grid point array. */ void RS_Grid::updatePointArray() { RS_DEBUG->print("RS_Grid::update"); if (graphicView->isGridOn()) { RS_Graphic* graphic = graphicView->getGraphic(); // auto scale grid? RS_SETTINGS->beginGroup("/Appearance"); bool scaleGrid = (bool)RS_SETTINGS->readNumEntry("/ScaleGrid", 1); // get grid setting RS_Vector userGrid; if (graphic!=NULL) { //$ISOMETRICGRID == $SNAPSTYLE isometric = static_cast<bool>(graphic->getVariableInt("$SNAPSTYLE",0)); crosshairType=graphic->getCrosshairType(); userGrid = graphic->getVariableVector("$GRIDUNIT", RS_Vector(-1.0, -1.0)); }else { isometric = (bool)RS_SETTINGS->readNumEntry("/IsometricGrid", 0); crosshairType=static_cast<RS2::CrosshairType>(RS_SETTINGS->readNumEntry("/CrosshairType",0)); userGrid.x = RS_SETTINGS->readEntry("/GridSpacingX",QString("-1")).toDouble(); userGrid.y = RS_SETTINGS->readEntry("/GridSpacingY",QString("-1")).toDouble(); } int minGridSpacing = RS_SETTINGS->readNumEntry("/MinGridSpacing", 10); RS_SETTINGS->endGroup(); // std::cout<<"Grid userGrid="<<userGrid<<std::endl; // delete old grid: if (pt!=NULL) { delete[] pt; pt = NULL; } if (metaX!=NULL) { delete[] metaX; metaX = NULL; } if (metaY!=NULL) { delete[] metaY; metaY = NULL; } number = 0; numMetaX = 0; numMetaY = 0; // RS_DEBUG->print("RS_Grid::update: 001"); // find out unit: RS2::Unit unit = RS2::None; RS2::LinearFormat format = RS2::Decimal; if (graphic!=NULL) { unit = graphic->getUnit(); format = graphic->getLinearFormat(); } RS_Vector gridWidth; // RS_Vector metaGridWidth; // RS_DEBUG->print("RS_Grid::update: 002"); // init grid spacing: // metric grid: if (RS_Units::isMetric(unit) || unit==RS2::None || format==RS2::Decimal || format==RS2::Engineering) { if (userGrid.x>0.0) { gridWidth.x = userGrid.x; } else { gridWidth.x = 1e-6; } if (userGrid.y>0.0) { gridWidth.y = userGrid.y; } else { gridWidth.y = 1e-6; } // RS_DEBUG->print("RS_Grid::update: 003"); // auto scale grid //scale grid by drawing setting as well, bug#3416862 // std::cout<<"RS_Grid::updatePointArray(): userGrid="<<userGrid<<std::endl; if (scaleGrid|| userGrid.x<=1e-6 || userGrid.y<=1e-6) { if(scaleGrid || userGrid.x<=1e-6) { while (graphicView->toGuiDX(gridWidth.x)<minGridSpacing) { gridWidth.x*=10; } } if(scaleGrid || userGrid.y<=1e-6) { while (graphicView->toGuiDY(gridWidth.y)<minGridSpacing) { gridWidth.y*=10; } } } // std::cout<<"RS_Grid::updatePointArray(): gridWidth="<<gridWidth<<std::endl; metaGridWidth.x = gridWidth.x*10; metaGridWidth.y = gridWidth.y*10; // RS_DEBUG->print("RS_Grid::update: 004"); } // imperial grid: else { // RS_DEBUG->print("RS_Grid::update: 005"); if (userGrid.x>0.0) { gridWidth.x = userGrid.x; } else { gridWidth.x = 1.0/1024.0; } if (userGrid.y>0.0) { gridWidth.y = userGrid.y; } else { gridWidth.y = 1.0/1024.0; } // RS_DEBUG->print("RS_Grid::update: 006"); if (unit==RS2::Inch) { // RS_DEBUG->print("RS_Grid::update: 007"); // auto scale grid //scale grid by drawing setting as well, bug#3416862 if (scaleGrid|| userGrid.x<=1e-6 || userGrid.y<=1e-6) { if(scaleGrid || userGrid.x<=1e-6) { while (graphicView->toGuiDX(gridWidth.x)<minGridSpacing) { if (RS_Math::round(gridWidth.x)>=36) { gridWidth.x*=2; } else if (RS_Math::round(gridWidth.x)>=12) { gridWidth.x*=3; } else if (RS_Math::round(gridWidth.x)>=4) { gridWidth.x*=3; } else if (RS_Math::round(gridWidth.x)>=1) { gridWidth.x*=2; } else { gridWidth.x*=2; } } } if(scaleGrid || userGrid.y<=1e-6) { while (graphicView->toGuiDY(gridWidth.y)<minGridSpacing) { if (RS_Math::round(gridWidth.y)>=36) { gridWidth.y*=2; } else if (RS_Math::round(gridWidth.y)>=12) { gridWidth.y*=3; } else if (RS_Math::round(gridWidth.y)>=4) { gridWidth.y*=3; } else if (RS_Math::round(gridWidth.y)>=1) { gridWidth.y*=2; } else { gridWidth.y*=2; } } } } // RS_DEBUG->print("RS_Grid::update: 008"); // metagrid X shows inches.. metaGridWidth.x = 1.0; if (graphicView->toGuiDX(metaGridWidth.x)<minGridSpacing*2) { // .. or feet metaGridWidth.x = 12.0; // .. or yards if (graphicView->toGuiDX(metaGridWidth.x)<minGridSpacing*2) { metaGridWidth.x = 36.0; // .. or miles (not really..) //if (graphicView->toGuiDX(metaGridWidth.x)<20) { // metaGridWidth.x = 63360.0; //} // .. or nothing if (graphicView->toGuiDX(metaGridWidth.x)<minGridSpacing*2) { metaGridWidth.x = -1.0; } } } // RS_DEBUG->print("RS_Grid::update: 009"); // metagrid Y shows inches.. metaGridWidth.y = 1.0; if (graphicView->toGuiDY(metaGridWidth.y)<minGridSpacing*2) { // .. or feet metaGridWidth.y = 12.0; // .. or yards if (graphicView->toGuiDY(metaGridWidth.y)<minGridSpacing*2) { metaGridWidth.y = 36.0; // .. or miles (not really..) //if (graphicView->toGuiDY(metaGridWidth.y)<20) { // metaGridWidth.y = 63360.0; //} // .. or nothing if (graphicView->toGuiDY(metaGridWidth.y)<minGridSpacing*2) { metaGridWidth.y = -1.0; } } } // RS_DEBUG->print("RS_Grid::update: 010"); } else { // RS_DEBUG->print("RS_Grid::update: 011"); if (scaleGrid) { while (graphicView->toGuiDX(gridWidth.x)<minGridSpacing) { gridWidth.x*=2; } metaGridWidth.x = -1.0; while (graphicView->toGuiDY(gridWidth.y)<minGridSpacing) { gridWidth.y*=2; } metaGridWidth.y = -1.0; } // RS_DEBUG->print("RS_Grid::update: 012"); } //gridWidth.y = gridWidth.x; //metaGridWidth.y = metaGridWidth.x; } // RS_DEBUG->print("RS_Grid::update: 013"); // for grid info: spacing = gridWidth.x; metaSpacing = metaGridWidth.x; //std::cout<<"Grid spacing="<<spacing<<std::endl; //std::cout<<"Grid metaSpacing="<<metaSpacing<<std::endl; if (gridWidth.x>1.0e-6 && gridWidth.y>1.0e-6 && graphicView->toGuiDX(gridWidth.x)>2 && graphicView->toGuiDY(gridWidth.y)>2) { // find grid boundaries double left = (int)(graphicView->toGraphX(0) / gridWidth.x) * gridWidth.x; double right = (int)(graphicView->toGraphX(graphicView->getWidth()) / gridWidth.x) * gridWidth.x; double top = (int)(graphicView->toGraphY(0) / gridWidth.y) * gridWidth.y; double bottom = (int)(graphicView->toGraphY(graphicView->getHeight()) / gridWidth.y) * gridWidth.y; left -= gridWidth.x; right += gridWidth.x; top += gridWidth.y; bottom -= gridWidth.y; // calculate number of visible grid points if(isometric){ int numberY = (RS_Math::round((top-bottom) / gridWidth.y) + 1); double dx=sqrt(3.)*gridWidth.y; cellV.set(fabs(dx),fabs(gridWidth.y)); double hdx=0.5*dx; double hdy=0.5*gridWidth.y; int numberX = (RS_Math::round((right-left) / dx) + 1); number = 2*numberX*numberY; baseGrid.set(left+remainder(-left,dx),bottom+remainder(-bottom,fabs(gridWidth.y))); if (number>0 && number<1000000) { pt = new RS_Vector[number]; int i=0; RS_Vector bp0(baseGrid),dbp1(hdx,hdy); for (int y=0; y<numberY; ++y) { RS_Vector bp1(bp0); for (int x=0; x<numberX; ++x) { pt[i++] = bp1; pt[i++] = bp1+dbp1; bp1.x += dx; } bp0.y += gridWidth.y; } //find metaGrid if (metaGridWidth.y>1.0e-6 && graphicView->toGuiDY(metaGridWidth.y)>2) { metaGridWidth.x=(metaGridWidth.x<0.)?-sqrt(3.)*fabs(metaGridWidth.y):sqrt(3.)*fabs(metaGridWidth.y); RS_Vector baseMetaGrid(left+remainder(-left,metaGridWidth.x)-fabs(metaGridWidth.x),bottom+remainder(-bottom,metaGridWidth.y)-fabs(metaGridWidth.y)); // calculate number of visible meta grid lines: numMetaX = (RS_Math::round((right-left) / metaGridWidth.x) + 1); numMetaY = (RS_Math::round((top-bottom) / metaGridWidth.y) + 1); if (numMetaX>0 && numMetaY>0) { // create meta grid arrays: metaX = new double[numMetaX]; metaY = new double[numMetaY]; double x0(baseMetaGrid.x); for (int i=0; i<numMetaX; x0 += metaGridWidth.x) { metaX[i++] = x0; } x0=baseMetaGrid.y; for (int i=0; i<numMetaY; x0 += metaGridWidth.y) { metaY[i++] = x0; } return; } numMetaX = 0; metaX = NULL; numMetaY = 0; metaY = NULL; return; } } number = 0; pt = NULL; numMetaX = 0; metaX = NULL; numMetaY = 0; metaY = NULL; }else{ cellV.set(fabs(gridWidth.x),fabs(gridWidth.y)); int numberX = (RS_Math::round((right-left) / gridWidth.x) + 1); int numberY = (RS_Math::round((top-bottom) / gridWidth.y) + 1); number = numberX*numberY; // RS_DEBUG->print("RS_Grid::update: 014"); // if(baseGrid.valid){//align to previous grid // baseGrid.set(left+remainder(baseGrid.x-left,dx),bottom+remainder(baseGrid.y-bottom,gridWidth.y)); // }else{ // baseGrid.set(left,bottom); // } //todo, fix baseGrid for orthogonal grid baseGrid.set(left,bottom); // create grid array: if (number>0 && number<1000000) { pt = new RS_Vector[number]; int i=0; RS_Vector bp0(baseGrid); for (int y=0; y<numberY; ++y) { RS_Vector bp1(bp0); for (int x=0; x<numberX; ++x) { pt[i++] = bp1; bp1.x += gridWidth.x; } bp0.y += gridWidth.y; } // find meta grid boundaries if (metaGridWidth.x>1.0e-6 && metaGridWidth.y>1.0e-6 && graphicView->toGuiDX(metaGridWidth.x)>2 && graphicView->toGuiDY(metaGridWidth.y)>2) { double mleft = (int)(graphicView->toGraphX(0) / metaGridWidth.x) * metaGridWidth.x; double mright = (int)(graphicView->toGraphX(graphicView->getWidth()) / metaGridWidth.x) * metaGridWidth.x; double mtop = (int)(graphicView->toGraphY(0) / metaGridWidth.y) * metaGridWidth.y; double mbottom = (int)(graphicView->toGraphY(graphicView->getHeight()) / metaGridWidth.y) * metaGridWidth.y; mleft -= metaGridWidth.x; mright += metaGridWidth.x; mtop += metaGridWidth.y; mbottom -= metaGridWidth.y; // calculate number of visible meta grid lines: numMetaX = (RS_Math::round((mright-mleft) / metaGridWidth.x) + 1); numMetaY = (RS_Math::round((mtop-mbottom) / metaGridWidth.y) + 1); if (numMetaX>0 && numMetaY>0) { // create meta grid arrays: metaX = new double[numMetaX]; metaY = new double[numMetaY]; int i=0; for (int x=0; x<numMetaX; ++x) { metaX[i++] = mleft+x*metaGridWidth.x; } i=0; for (int y=0; y<numMetaY; ++y) { metaY[i++] = mbottom+y*metaGridWidth.y; } return; } numMetaX = 0; metaX = NULL; numMetaY = 0; metaY = NULL; } return; } number = 0; pt = NULL; numMetaX = 0; metaX = NULL; numMetaY = 0; metaY = NULL; } // RS_DEBUG->print("RS_Grid::update: 015"); } } // RS_DEBUG->print("RS_Grid::update: OK"); }
/** * Updates the grid point array. */ void RS_Grid::update() { RS_DEBUG->print("RS_Grid::update"); if (graphicView->isGridOn()) { RS_Graphic* graphic = graphicView->getGraphic(); // auto scale grid? RS_SETTINGS->beginGroup("/Appearance"); bool scaleGrid = (bool)RS_SETTINGS->readNumEntry("/ScaleGrid", 1); int minGridSpacing = RS_SETTINGS->readNumEntry("/MinGridSpacing", 10); RS_SETTINGS->endGroup(); // get grid setting RS_Vector userGrid; if (graphic!=NULL) { userGrid = graphic->getVariableVector("$GRIDUNIT", RS_Vector(-1.0, -1.0)); } // delete old grid: if (pt!=NULL) { delete[] pt; pt = NULL; } if (metaX!=NULL) { delete[] metaX; metaX = NULL; } if (metaY!=NULL) { delete[] metaY; metaY = NULL; } number = 0; numMetaX = 0; numMetaY = 0; RS_DEBUG->print("RS_Grid::update: 001"); // find out unit: RS2::Unit unit = RS2::None; RS2::LinearFormat format = RS2::Decimal; if (graphic!=NULL) { unit = graphic->getUnit(); format = graphic->getLinearFormat(); } RS_Vector gridWidth; RS_Vector metaGridWidth; RS_DEBUG->print("RS_Grid::update: 002"); // init grid spacing: // metric grid: if (RS_Units::isMetric(unit) || unit==RS2::None || format==RS2::Decimal || format==RS2::Engineering) { if (userGrid.x>0.0) { gridWidth.x = userGrid.x; } else { gridWidth.x = 0.000001; } if (userGrid.y>0.0) { gridWidth.y = userGrid.y; } else { gridWidth.y = 0.000001; } RS_DEBUG->print("RS_Grid::update: 003"); // auto scale grid if (scaleGrid) { while (graphicView->toGuiDX(gridWidth.x)<minGridSpacing) { gridWidth.x*=10; } while (graphicView->toGuiDY(gridWidth.y)<minGridSpacing) { gridWidth.y*=10; } } metaGridWidth.x = gridWidth.x*10; metaGridWidth.y = gridWidth.y*10; RS_DEBUG->print("RS_Grid::update: 004"); } // imperial grid: else { RS_DEBUG->print("RS_Grid::update: 005"); if (userGrid.x>0.0) { gridWidth.x = userGrid.x; } else { gridWidth.x = 1.0/1024.0; } if (userGrid.y>0.0) { gridWidth.y = userGrid.y; } else { gridWidth.y = 1.0/1024.0; } RS_DEBUG->print("RS_Grid::update: 006"); if (unit==RS2::Inch) { RS_DEBUG->print("RS_Grid::update: 007"); // auto scale grid if (scaleGrid) { while (graphicView->toGuiDX(gridWidth.x)<minGridSpacing) { if (RS_Math::round(gridWidth.x)>=36) { gridWidth.x*=2; } else if (RS_Math::round(gridWidth.x)>=12) { gridWidth.x*=3; } else if (RS_Math::round(gridWidth.x)>=4) { gridWidth.x*=3; } else if (RS_Math::round(gridWidth.x)>=1) { gridWidth.x*=2; } else { gridWidth.x*=2; } } while (graphicView->toGuiDY(gridWidth.y)<minGridSpacing) { if (RS_Math::round(gridWidth.y)>=36) { gridWidth.y*=2; } else if (RS_Math::round(gridWidth.y)>=12) { gridWidth.y*=3; } else if (RS_Math::round(gridWidth.y)>=4) { gridWidth.y*=3; } else if (RS_Math::round(gridWidth.y)>=1) { gridWidth.y*=2; } else { gridWidth.y*=2; } } } RS_DEBUG->print("RS_Grid::update: 008"); // metagrid X shows inches.. metaGridWidth.x = 1.0; if (graphicView->toGuiDX(metaGridWidth.x)<minGridSpacing*2) { // .. or feet metaGridWidth.x = 12.0; // .. or yards if (graphicView->toGuiDX(metaGridWidth.x)<minGridSpacing*2) { metaGridWidth.x = 36.0; // .. or miles (not really..) //if (graphicView->toGuiDX(metaGridWidth.x)<20) { // metaGridWidth.x = 63360.0; //} // .. or nothing if (graphicView->toGuiDX(metaGridWidth.x)<minGridSpacing*2) { metaGridWidth.x = -1.0; } } } RS_DEBUG->print("RS_Grid::update: 009"); // metagrid Y shows inches.. metaGridWidth.y = 1.0; if (graphicView->toGuiDY(metaGridWidth.y)<minGridSpacing*2) { // .. or feet metaGridWidth.y = 12.0; // .. or yards if (graphicView->toGuiDY(metaGridWidth.y)<minGridSpacing*2) { metaGridWidth.y = 36.0; // .. or miles (not really..) //if (graphicView->toGuiDY(metaGridWidth.y)<20) { // metaGridWidth.y = 63360.0; //} // .. or nothing if (graphicView->toGuiDY(metaGridWidth.y)<minGridSpacing*2) { metaGridWidth.y = -1.0; } } } RS_DEBUG->print("RS_Grid::update: 010"); } else { RS_DEBUG->print("RS_Grid::update: 011"); if (scaleGrid) { while (graphicView->toGuiDX(gridWidth.x)<minGridSpacing) { gridWidth.x*=2; } metaGridWidth.x = -1.0; while (graphicView->toGuiDY(gridWidth.y)<minGridSpacing) { gridWidth.y*=2; } metaGridWidth.y = -1.0; } RS_DEBUG->print("RS_Grid::update: 012"); } //gridWidth.y = gridWidth.x; //metaGridWidth.y = metaGridWidth.x; } RS_DEBUG->print("RS_Grid::update: 013"); // for grid info: spacing = gridWidth.x; metaSpacing = metaGridWidth.x; if (gridWidth.x>1.0e-6 && gridWidth.y>1.0e-6 && graphicView->toGuiDX(gridWidth.x)>2 && graphicView->toGuiDY(gridWidth.y)>2) { // find grid boundaries double left = (int)(graphicView->toGraphX(0) / gridWidth.x) * gridWidth.x; double right = (int)(graphicView->toGraphX(graphicView->getWidth()) / gridWidth.x) * gridWidth.x; double top = (int)(graphicView->toGraphY(0) / gridWidth.y) * gridWidth.y; double bottom = (int)(graphicView->toGraphY(graphicView->getHeight()) / gridWidth.y) * gridWidth.y; left -= gridWidth.x; right += gridWidth.x; top += gridWidth.y; bottom -= gridWidth.y; // calculate number of visible grid points int numberX = (RS_Math::round((right-left) / gridWidth.x) + 1); int numberY = (RS_Math::round((top-bottom) / gridWidth.y) + 1); number = numberX*numberY; RS_DEBUG->print("RS_Grid::update: 014"); // create grid array: if (number>0 && number<1000000) { pt = new RS_Vector[number]; int i=0; for (int y=0; y<numberY; ++y) { for (int x=0; x<numberX; ++x) { pt[i++] = RS_Vector(left+x*gridWidth.x, bottom+y*gridWidth.y); } } } else { number = 0; pt = NULL; } RS_DEBUG->print("RS_Grid::update: 015"); } // find meta grid boundaries if (metaGridWidth.x>1.0e-6 && metaGridWidth.y>1.0e-6 && graphicView->toGuiDX(metaGridWidth.x)>2 && graphicView->toGuiDY(metaGridWidth.y)>2) { double mleft = (int)(graphicView->toGraphX(0) / metaGridWidth.x) * metaGridWidth.x; double mright = (int)(graphicView->toGraphX(graphicView->getWidth()) / metaGridWidth.x) * metaGridWidth.x; double mtop = (int)(graphicView->toGraphY(0) / metaGridWidth.y) * metaGridWidth.y; double mbottom = (int)(graphicView->toGraphY(graphicView->getHeight()) / metaGridWidth.y) * metaGridWidth.y; mleft -= metaGridWidth.x; mright += metaGridWidth.x; mtop += metaGridWidth.y; mbottom -= metaGridWidth.y; // calculate number of visible meta grid lines: numMetaX = (RS_Math::round((mright-mleft) / metaGridWidth.x) + 1); numMetaY = (RS_Math::round((mtop-mbottom) / metaGridWidth.y) + 1); if (numMetaX>0 && numMetaY>0) { // create meta grid arrays: metaX = new double[numMetaX]; metaY = new double[numMetaY]; int i=0; for (int x=0; x<numMetaX; ++x) { metaX[i++] = mleft+x*metaGridWidth.x; } i=0; for (int y=0; y<numMetaY; ++y) { metaY[i++] = mbottom+y*metaGridWidth.y; } } else { numMetaX = 0; metaX = NULL; numMetaY = 0; metaY = NULL; } } } RS_DEBUG->print("RS_Grid::update: OK"); }