X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Fdrawing.cpp;h=d376e049a4bb12c80e5104407a096723b7303955;hb=5adb444f3e523d3fd028617ced72d1ea6661db21;hp=dbdc1e2f8716e4c7abb3e2382f0087fd462b3172;hpb=89e127aa3dbd74d3158e6dbe0ca1703420c04395;p=architektonas diff --git a/src/base/drawing.cpp b/src/base/drawing.cpp index dbdc1e2..d376e04 100644 --- a/src/base/drawing.cpp +++ b/src/base/drawing.cpp @@ -3,7 +3,9 @@ // Part of the Architektonas Project // Originally part of QCad Community Edition by Andrew Mustun // Extensively rewritten and refactored by James L. Hammons -// (C) 2010 Underground Software +// Portions copyright (C) 2001-2003 RibbonSoft +// Copyright (C) 2010 Underground Software +// See the README and GPLv2 files for licensing and warranty information // // JLH = James L. Hammons // @@ -17,23 +19,23 @@ #include "drawing.h" -#include "rs_debug.h" -#include "rs_fileio.h" -#include "rs_math.h" -#include "rs_units.h" +#include "debug.h" +#include "fileio.h" +#include "mathextra.h" +#include "units.h" #include "settings.h" /** * Default constructor. */ -Drawing::Drawing(RS_EntityContainer * parent): RS_Document(parent), layerList(), +Drawing::Drawing(EntityContainer * parent): Document(parent), layerList(), blockList(true) #ifdef RS_CAM , camData() #endif { settings.beginGroup("Defaults"); - setUnit(RS_Units::stringToUnit(settings.value("Unit", "None").toString())); + setUnit(Units::stringToUnit(settings.value("Unit", "None").toString())); settings.endGroup(); RS2::Unit unit = getUnit(); @@ -48,11 +50,11 @@ Drawing::Drawing(RS_EntityContainer * parent): RS_Document(parent), layerList(), } else { - addVariable("$DIMASZ", RS_Units::convert(2.5, RS2::Millimeter, unit), 40); - addVariable("$DIMEXE", RS_Units::convert(1.25, RS2::Millimeter, unit), 40); - addVariable("$DIMEXO", RS_Units::convert(0.625, RS2::Millimeter, unit), 40); - addVariable("$DIMGAP", RS_Units::convert(0.625, RS2::Millimeter, unit), 40); - addVariable("$DIMTXT", RS_Units::convert(2.5, RS2::Millimeter, unit), 40); + addVariable("$DIMASZ", Units::convert(2.5, RS2::Millimeter, unit), 40); + addVariable("$DIMEXE", Units::convert(1.25, RS2::Millimeter, unit), 40); + addVariable("$DIMEXO", Units::convert(0.625, RS2::Millimeter, unit), 40); + addVariable("$DIMGAP", Units::convert(0.625, RS2::Millimeter, unit), 40); + addVariable("$DIMTXT", Units::convert(2.5, RS2::Millimeter, unit), 40); } setModified(false); @@ -74,13 +76,13 @@ Drawing::~Drawing() /** * Counts the entities on the given layer. */ -unsigned long int Drawing::countLayerEntities(RS_Layer * layer) +unsigned long int Drawing::countLayerEntities(Layer * layer) { int c = 0; if (layer != NULL) { - for(RS_Entity * t=firstEntity(RS2::ResolveNone); t!=NULL; t=nextEntity(RS2::ResolveNone)) + for(Entity * t=firstEntity(RS2::ResolveNone); t!=NULL; t=nextEntity(RS2::ResolveNone)) { if (t->getLayer()!=NULL && t->getLayer()->getName()==layer->getName()) { @@ -92,12 +94,12 @@ unsigned long int Drawing::countLayerEntities(RS_Layer * layer) return c; } -/*virtual*/ RS_LayerList * Drawing::getLayerList() +/*virtual*/ LayerList * Drawing::getLayerList() { return &layerList; } -/*virtual*/ RS_BlockList * Drawing::getBlockList() +/*virtual*/ BlockList * Drawing::getBlockList() { return &blockList; } @@ -108,15 +110,15 @@ unsigned long int Drawing::countLayerEntities(RS_Layer * layer) */ void Drawing::newDoc() { - RS_DEBUG->print("Drawing::newDoc"); + DEBUG->print("Drawing::newDoc"); clear(); clearLayers(); clearBlocks(); - addLayer(new RS_Layer("0")); - //addLayer(new RS_Layer("ByBlock")); + addLayer(new Layer("0")); + //addLayer(new Layer("ByBlock")); setModified(false); } @@ -128,12 +130,11 @@ bool Drawing::save() { bool ret = false; - RS_DEBUG->print("Drawing::save"); - RS_DEBUG->print(" file: %s", filename.toLatin1().data()); - RS_DEBUG->print(" format: %d", (int)formatType); - - RS_DEBUG->print(" export..."); - ret = RS_FILEIO->fileExport(*this, filename, formatType); + DEBUG->print("Drawing::save"); + DEBUG->print(" file: %s", filename.toLatin1().data()); + DEBUG->print(" format: %d", (int)formatType); + DEBUG->print(" export..."); + ret = FILEIO->fileExport(*this, filename, formatType); if (ret) { @@ -142,7 +143,7 @@ bool Drawing::save() blockList.setModified(false); } - RS_DEBUG->print("Drawing::save ok"); + DEBUG->print("Drawing::save ok"); return ret; } @@ -152,7 +153,7 @@ bool Drawing::save() */ bool Drawing::saveAs(const QString & filename, RS2::FormatType type) { - RS_DEBUG->print("Drawing::saveAs"); + DEBUG->print("Drawing::saveAs"); this->filename = filename; this->formatType = type; @@ -161,30 +162,24 @@ bool Drawing::saveAs(const QString & filename, RS2::FormatType type) } /** - * Loads the given fils into this graphic. + * Loads the given file into this graphic. */ -bool Drawing::open(const QString &filename, RS2::FormatType type) +bool Drawing::open(const QString & filename, RS2::FormatType type) { - RS_DEBUG->print("Drawing::open(%s)", filename.toLatin1().data()); - + DEBUG->print("Drawing::open(%s)", filename.toLatin1().data()); bool ret = false; - this->filename = filename; - // clean all: newDoc(); - // import file: - ret = RS_FILEIO->fileImport(*this, filename, type); - + ret = FILEIO->fileImport(*this, filename, type); setModified(false); layerList.setModified(false); blockList.setModified(false); //cout << *((Drawing*)graphic); //calculateBorders(); - - RS_DEBUG->print("Drawing::open(%s): OK", filename.toLatin1().data()); + DEBUG->print("Drawing::open(%s): OK", filename.toLatin1().data()); return ret; } @@ -200,7 +195,7 @@ uint Drawing::countLayers() const return layerList.count(); } -RS_Layer * Drawing::layerAt(uint i) +Layer * Drawing::layerAt(uint i) { return layerList.at(i); } @@ -210,17 +205,17 @@ void Drawing::activateLayer(const QString & name) layerList.activate(name); } -void Drawing::activateLayer(RS_Layer * layer) +void Drawing::activateLayer(Layer * layer) { layerList.activate(layer); } -RS_Layer * Drawing::getActiveLayer() +Layer * Drawing::getActiveLayer() { return layerList.getActive(); } -/*virtual*/ void Drawing::addLayer(RS_Layer * layer) +/*virtual*/ void Drawing::addLayer(Layer * layer) { layerList.add(layer); } @@ -228,16 +223,16 @@ RS_Layer * Drawing::getActiveLayer() /** * Removes the given layer and undoes all entities on it. */ -/*virtual*/ void Drawing::removeLayer(RS_Layer * layer) +/*virtual*/ void Drawing::removeLayer(Layer * layer) { if (layer != NULL && layer->getName() != "0") { // remove all entities on that layer: startUndoCycle(); - for(RS_Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone)) + for(Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone)) { - if (e->getLayer() != NULL && e->getLayer()->getName() == layer->getName()) + if (e->getLayer() && e->getLayer()->getName() == layer->getName()) { e->setUndoState(true); e->setLayer("0"); @@ -250,11 +245,11 @@ RS_Layer * Drawing::getActiveLayer() // remove all entities in blocks that are on that layer: for(uint bi=0; bifirstEntity(RS2::ResolveNone); e!=NULL; e=blk->nextEntity(RS2::ResolveNone)) + for(Entity * e=blk->firstEntity(RS2::ResolveNone); e!=NULL; e=blk->nextEntity(RS2::ResolveNone)) { if (e->getLayer() != NULL && e->getLayer()->getName() == layer->getName()) { @@ -270,12 +265,12 @@ RS_Layer * Drawing::getActiveLayer() } } -/*virtual*/ void Drawing::editLayer(RS_Layer * layer, const RS_Layer & source) +/*virtual*/ void Drawing::editLayer(Layer * layer, const Layer & source) { layerList.edit(layer, source); } -RS_Layer * Drawing::findLayer(const QString & name) +Layer * Drawing::findLayer(const QString & name) { return layerList.find(name); } @@ -285,12 +280,12 @@ void Drawing::toggleLayer(const QString & name) layerList.toggle(name); } -void Drawing::toggleLayer(RS_Layer * layer) +void Drawing::toggleLayer(Layer * layer) { layerList.toggle(layer); } -void Drawing::toggleLayerLock(RS_Layer * layer) +void Drawing::toggleLayerLock(Layer * layer) { layerList.toggleLock(layer); } @@ -300,15 +295,17 @@ void Drawing::freezeAllLayers(bool freeze) layerList.freezeAll(freeze); } -void Drawing::addLayerListListener(RS_LayerListListener * listener) +#if 0 +void Drawing::addLayerListListener(LayerListListener * listener) { layerList.addListener(listener); } -void Drawing::removeLayerListListener(RS_LayerListListener * listener) +void Drawing::removeLayerListListener(LayerListListener * listener) { layerList.removeListener(listener); } +#endif // Wrapper for block functions: @@ -322,7 +319,7 @@ uint Drawing::countBlocks() return blockList.count(); } -RS_Block * Drawing::blockAt(uint i) +Block * Drawing::blockAt(uint i) { return blockList.at(i); } @@ -332,17 +329,17 @@ void Drawing::activateBlock(const QString & name) blockList.activate(name); } -void Drawing::activateBlock(RS_Block * block) +void Drawing::activateBlock(Block * block) { blockList.activate(block); } -RS_Block * Drawing::getActiveBlock() +Block * Drawing::getActiveBlock() { return blockList.getActive(); } -/*virtual*/ bool Drawing::addBlock(RS_Block * block, bool notify/*= true*/) +/*virtual*/ bool Drawing::addBlock(Block * block, bool notify/*= true*/) { return blockList.add(block, notify); } @@ -352,12 +349,12 @@ RS_Block * Drawing::getActiveBlock() blockList.addNotification(); } -/*virtual*/ void Drawing::removeBlock(RS_Block * block) +/*virtual*/ void Drawing::removeBlock(Block * block) { blockList.remove(block); } -RS_Block * Drawing::findBlock(const QString & name) +Block * Drawing::findBlock(const QString & name) { return blockList.find(name); } @@ -372,7 +369,7 @@ void Drawing::toggleBlock(const QString & name) blockList.toggle(name); } -void Drawing::toggleBlock(RS_Block * block) +void Drawing::toggleBlock(Block * block) { blockList.toggle(block); } @@ -382,15 +379,17 @@ void Drawing::freezeAllBlocks(bool freeze) blockList.freezeAll(freeze); } -void Drawing::addBlockListListener(RS_BlockListListener * listener) +#if 0 +void Drawing::addBlockListListener(BlockListListener * listener) { blockList.addListener(listener); } -void Drawing::removeBlockListListener(RS_BlockListListener * listener) +void Drawing::removeBlockListListener(BlockListListener * listener) { blockList.removeListener(listener); } +#endif // Wrappers for variable functions: void Drawing::clearVariables() @@ -448,8 +447,8 @@ void Drawing::removeVariable(const QString & key) variableDict.remove(key); } -//Q3Dict & getVariableDict() -QMultiHash & Drawing::getVariableDict() +//Q3Dict & getVariableDict() +QMultiHash & Drawing::getVariableDict() { return variableDict.getVariableDict(); } @@ -460,6 +459,7 @@ QMultiHash & Drawing::getVariableDict() bool Drawing::isGridOn() { int on = getVariableInt("$GRIDMODE", 1); + return (on != 0); } @@ -476,10 +476,8 @@ void Drawing::setGridOn(bool on) */ void Drawing::setUnit(RS2::Unit u) { - setPaperSize(RS_Units::convert(getPaperSize(), getUnit(), u)); - + setPaperSize(Units::convert(getPaperSize(), getUnit(), u)); addVariable("$INSUNITS", (int)u, 70); - //unit = u; } @@ -603,8 +601,7 @@ void Drawing::setPaperInsertionBase(const Vector & p) */ Vector Drawing::getPaperSize() { - Vector def = RS_Units::convert(Vector(210.0, 297.0), RS2::Millimeter, getUnit()); - + Vector def = Units::convert(Vector(210.0, 297.0), RS2::Millimeter, getUnit()); Vector v1 = getVariableVector("$PLIMMIN", Vector(0.0, 0.0)); Vector v2 = getVariableVector("$PLIMMAX", def); @@ -628,12 +625,12 @@ void Drawing::setPaperSize(const Vector & s) */ RS2::PaperFormat Drawing::getPaperFormat(bool * landscape) { - Vector size = RS_Units::convert(getPaperSize(), getUnit(), RS2::Millimeter); + Vector size = Units::convert(getPaperSize(), getUnit(), RS2::Millimeter); if (landscape != NULL) *landscape = (size.x > size.y); - return RS_Units::paperSizeToFormat(size); + return Units::paperSizeToFormat(size); } /** @@ -641,7 +638,7 @@ RS2::PaperFormat Drawing::getPaperFormat(bool * landscape) */ void Drawing::setPaperFormat(RS2::PaperFormat f, bool landscape) { - Vector size = RS_Units::paperFormatToSize(f); + Vector size = Units::paperFormatToSize(f); if (landscape) { @@ -651,7 +648,7 @@ void Drawing::setPaperFormat(RS2::PaperFormat f, bool landscape) } if (f != RS2::Custom) - setPaperSize(RS_Units::convert(size, RS2::Millimeter, getUnit())); + setPaperSize(Units::convert(size, RS2::Millimeter, getUnit())); } /** @@ -693,14 +690,14 @@ void Drawing::centerToPage() */ void Drawing::fitToPage() { - double border = RS_Units::convert(25.0, RS2::Millimeter, getUnit()); + double border = Units::convert(25.0, RS2::Millimeter, getUnit()); Vector ps = getPaperSize() - Vector(border, border); Vector s = getSize(); double fx = RS_MAXDOUBLE; double fy = RS_MAXDOUBLE; //double factor = 1.0; - //ps = RS_Units::convert(ps, getUnit(), RS2::Millimeter); + //ps = Units::convert(ps, getUnit(), RS2::Millimeter); if (fabs(s.x) > 1.0e-6) fx = ps.x / s.x; @@ -751,8 +748,8 @@ std::ostream & operator<<(std::ostream & os, Drawing & g) os << "--- Drawing: \n"; os << "---" << *g.getLayerList() << "\n"; os << "---" << *g.getBlockList() << "\n"; - os << "---" << (RS_Undo&)g << "\n"; - os << "---" << (RS_EntityContainer&)g << "\n"; + os << "---" << (Undo &)g << "\n"; + os << "---" << (EntityContainer &)g << "\n"; return os; }