📄 rs_entity.cpp
字号:
/** * 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, double val, int code) { RS_Graphic* graphic = getGraphic(); if (graphic!=NULL) { graphic->addVariable(key, val, code); }}/** * 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, int val, int code) { RS_Graphic* graphic = getGraphic(); if (graphic!=NULL) { graphic->addVariable(key, val, code); }}/** * 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); }}/** * 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;}/** * 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. */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 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;}/** * Returns a pointer to the layer this entity is on or NULL. * * @para resolve true: if the layer is ByBlock, the layer of the * block this entity is in is returned. * false: the layer of the entity is returned. * * @return pointer to the layer this entity is on. If the layer * is set to NULL the layer of the next parent that is not on * layer NULL is returned. If all parents are on layer NULL, NULL * is returned. */RS_Layer* RS_Entity::getLayer(bool resolve) const { if (resolve) { // we have no layer but a parent that might have one. // return parent's layer instead: if (layer==NULL /*|| layer->getName()=="ByBlock"*/) { if (parent!=NULL) { return parent->getLayer(true); } else { return NULL; } } } // return our layer. might still be NULL: return layer;}/** * 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; }}/** * Sets the layer of this entity to the layer given. */void RS_Entity::setLayer(RS_Layer* l) { layer = l;}/** * 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; }}/** * Gets the pen needed to draw this entity. * The attributes can also come from the layer this entity is on * if the flags are set accordingly. * * @param resolve true: Resolve the pen to a drawable pen (e.g. the pen * from the layer or parent..) * false: Don't resolve and return a pen or ByLayer, ByBlock, ... * * @return Pen for this entity. */RS_Pen RS_Entity::getPen(bool resolve) const { if (!resolve) { return pen; } else { RS_Pen p = pen; RS_Layer* l = getLayer(true); // use parental attributes (e.g. vertex of a polyline, block // entities when they are drawn in block documents): if (!p.isValid() || p.getColor().isByBlock()) { if (parent!=NULL) { p = parent->getPen(); } } // use layer attributes: else if (l!=NULL) { // layer is "ByBlock": /*if (layer->getName()=="ByBlock" && getBlockOrInsert()!=NULL) { p = getBlockOrInsert()->getPen(); } else {*/ // use layer's color: if (p.getColor().isByLayer()) { p.setColor(l->getPen().getColor()); } // use layer's width: if (p.getWidth()==RS2::WidthByLayer) { p.setWidth(l->getPen().getWidth()); } // use layer's linetype: if (p.getLineType()==RS2::LineByLayer) { p.setLineType(l->getPen().getLineType()); } //} } return p; }}/** * Sets the pen of this entity to the current pen of * the graphic this entity is in. If this entity (and none * of its parents) are in a graphic the pen is not changed. */void RS_Entity::setPenToActive() { RS_Document* doc = getDocument(); if (doc!=NULL) { pen = doc->getActivePen(); } else { //RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Entity::setPenToActive(): " // "No document / active pen linked to this entity."); } //else { // pen = RS_Pen(); //}}/** * Implementations must stretch the given range of the entity * by the given offset. This default implementation moves the * whole entity if it is completely inside the given range. */void RS_Entity::stretch(RS_Vector firstCorner, RS_Vector secondCorner, RS_Vector offset) { //e->calculateBorders(); if (getMin().isInWindow(firstCorner, secondCorner) && getMax().isInWindow(firstCorner, secondCorner)) { move(offset); }}/** * @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;}/** * @return User defined variable connected to this entity. */RS_String* RS_Entity::getUserDefVar(RS_String key) { return (this->varList.find(key));}/** * Add a user defined variable to this entity. */void RS_Entity::setUserDefVar(RS_String key, RS_String val) { varList.insert(key, new RS_String(val));}/** * Deletes the given user defined variable. */void RS_Entity::delUserDefVar(RS_String key) { varList.remove(key);}/** * @return A list of all keys connected to this entity. */RS_StringList RS_Entity::getAllKeys() { RS_StringList keys; RS_DictIterator<RS_String> it(varList); for( ; it.current(); ++it ) keys.append(it.currentKey()); return keys;}/** * Dumps the elements data to stdout. */std::ostream& operator << (std::ostream& os, RS_Entity& e) { //os << "Warning: Virtual entity!\n"; //return os; os << " {Entity id: " << e.id; if (e.parent!=NULL) { os << " | parent id: " << e.parent->getId() << "\n"; } else { os << " | no parent\n"; } os << " flags: " << (e.getFlag(RS2::FlagVisible) ? "RS2::FlagVisible" : ""); os << (e.getFlag(RS2::FlagUndone) ? " RS2::FlagUndone" : ""); os << (e.getFlag(RS2::FlagSelected) ? " RS2::FlagSelected" : ""); os << "\n"; if (e.layer==NULL) { os << " layer: NULL "; } else { os << " layer: " << e.layer->getName().latin1() << " "; os << " layer address: " << (int)(e.layer) << " "; } os << e.pen << "\n"; os << "variable list:\n"; RS_DictIterator<RS_String> it(e.varList); // See QDictIterator for( ; it.current(); ++it ) { os << it.currentKey() << ": " << *it.current() << ", "; } // There should be a better way then this... switch(e.rtti()) { case RS2::EntityPoint: os << (RS_Point&)e; break; case RS2::EntityLine: os << (RS_Line&)e; break; case RS2::EntityPolyline: os << (RS_Polyline&)e; break; case RS2::EntityArc: os << (RS_Arc&)e; break; case RS2::EntityCircle: os << (RS_Circle&)e; break; case RS2::EntityEllipse: os << (RS_Ellipse&)e; break; case RS2::EntityInsert: os << (RS_Insert&)e; break; case RS2::EntityText: os << (RS_Text&)e; break; default: os << "Unknown Entity"; break; } os << "}\n\n"; return os;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -