DXF: export color as indexed, not RGB.
The version of AutoCAD we advertise is unable to read RGB color, so software attempting to be compatible with it ignores color attributes.
This commit is contained in:
parent
e129755d66
commit
7b8e8b0b41
|
@ -10,8 +10,7 @@
|
||||||
|
|
||||||
void Constraint::LineDrawOrGetDistance(Vector a, Vector b) {
|
void Constraint::LineDrawOrGetDistance(Vector a, Vector b) {
|
||||||
if(dogd.drawing) {
|
if(dogd.drawing) {
|
||||||
hStyle hs = disp.style;
|
hStyle hs = GetStyle();
|
||||||
if(hs.v == 0) hs.v = Style::CONSTRAINT;
|
|
||||||
|
|
||||||
if(dogd.sel) {
|
if(dogd.sel) {
|
||||||
dogd.sel->AddEdge(a, b, hs.v);
|
dogd.sel->AddEdge(a, b, hs.v);
|
||||||
|
@ -70,8 +69,7 @@ std::string Constraint::Label(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Constraint::DoLabel(Vector ref, Vector *labelPos, Vector gr, Vector gu) {
|
void Constraint::DoLabel(Vector ref, Vector *labelPos, Vector gr, Vector gu) {
|
||||||
hStyle hs = disp.style;
|
hStyle hs = GetStyle();
|
||||||
if(hs.v == 0) hs.v = Style::CONSTRAINT;
|
|
||||||
double th = Style::TextHeight(hs);
|
double th = Style::TextHeight(hs);
|
||||||
|
|
||||||
std::string s = Label();
|
std::string s = Label();
|
||||||
|
@ -141,8 +139,7 @@ void Constraint::DoProjectedPoint(Vector *r) {
|
||||||
// depending whether that extension was from A or from B.
|
// depending whether that extension was from A or from B.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
int Constraint::DoLineTrimmedAgainstBox(Vector ref, Vector a, Vector b, bool extend) {
|
int Constraint::DoLineTrimmedAgainstBox(Vector ref, Vector a, Vector b, bool extend) {
|
||||||
hStyle hs = disp.style;
|
hStyle hs = GetStyle();
|
||||||
if(hs.v == 0) hs.v = Style::CONSTRAINT;
|
|
||||||
double th = Style::TextHeight(hs);
|
double th = Style::TextHeight(hs);
|
||||||
Vector gu = SS.GW.projUp.WithMagnitude(1),
|
Vector gu = SS.GW.projUp.WithMagnitude(1),
|
||||||
gr = SS.GW.projRight.WithMagnitude(1);
|
gr = SS.GW.projRight.WithMagnitude(1);
|
||||||
|
@ -1176,8 +1173,7 @@ s:
|
||||||
void Constraint::Draw(void) {
|
void Constraint::Draw(void) {
|
||||||
dogd.drawing = true;
|
dogd.drawing = true;
|
||||||
dogd.sel = NULL;
|
dogd.sel = NULL;
|
||||||
hStyle hs = disp.style;
|
hStyle hs = GetStyle();
|
||||||
if(hs.v == 0) hs.v = Style::CONSTRAINT;
|
|
||||||
|
|
||||||
ssglLineWidth(Style::Width(hs));
|
ssglLineWidth(Style::Width(hs));
|
||||||
ssglColorRGB(Style::Color(hs));
|
ssglColorRGB(Style::Color(hs));
|
||||||
|
@ -1229,6 +1225,11 @@ bool Constraint::IsStylable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hStyle Constraint::GetStyle() const {
|
||||||
|
if(disp.style.v != 0) return disp.style;
|
||||||
|
return { Style::CONSTRAINT };
|
||||||
|
}
|
||||||
|
|
||||||
bool Constraint::HasLabel() {
|
bool Constraint::HasLabel() {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case COMMENT:
|
case COMMENT:
|
||||||
|
|
|
@ -306,7 +306,7 @@ public:
|
||||||
Vector bp = SK.GetEntity(c->ptB)->PointGetNum();
|
Vector bp = SK.GetEntity(c->ptB)->PointGetNum();
|
||||||
Vector ref = ((ap.Plus(bp)).ScaledBy(0.5)).Plus(c->disp.offset);
|
Vector ref = ((ap.Plus(bp)).ScaledBy(0.5)).Plus(c->disp.offset);
|
||||||
writeAlignedDimension(xfrm(ap), xfrm(bp), xfrm(ref),
|
writeAlignedDimension(xfrm(ap), xfrm(bp), xfrm(ref),
|
||||||
xfrm(ref), c->Label());
|
xfrm(ref), c->Label(), c->GetStyle());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ public:
|
||||||
Vector xdl = xfrm(lB).Minus(xfrm(lA));
|
Vector xdl = xfrm(lB).Minus(xfrm(lA));
|
||||||
writeLinearDimension(xfrm(pt), xfrm(refClosest), xfrm(ref),
|
writeLinearDimension(xfrm(pt), xfrm(refClosest), xfrm(ref),
|
||||||
xfrm(ref), c->Label(),
|
xfrm(ref), c->Label(),
|
||||||
atan2(xdl.y, xdl.x) / PI * 180.0 + 90.0, 0.0);
|
atan2(xdl.y, xdl.x) / PI * 180.0 + 90.0, 0.0, c->GetStyle());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,11 +356,11 @@ public:
|
||||||
if(/*isRadius*/c->other) {
|
if(/*isRadius*/c->other) {
|
||||||
writeRadialDimension(
|
writeRadialDimension(
|
||||||
xfrm(center), xfrm(center.Plus(rad)),
|
xfrm(center), xfrm(center.Plus(rad)),
|
||||||
xfrm(ref), c->Label());
|
xfrm(ref), c->Label(), c->GetStyle());
|
||||||
} else {
|
} else {
|
||||||
writeDiametricDimension(
|
writeDiametricDimension(
|
||||||
xfrm(center.Minus(rad)), xfrm(center.Plus(rad)),
|
xfrm(center.Minus(rad)), xfrm(center.Plus(rad)),
|
||||||
xfrm(ref), c->Label());
|
xfrm(ref), c->Label(), c->GetStyle());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -386,15 +386,15 @@ public:
|
||||||
|
|
||||||
writeAngularDimension(
|
writeAngularDimension(
|
||||||
xfrm(a0), xfrm(a0.Plus(da)), xfrm(b0), xfrm(b0.Plus(db)), xfrm(ref),
|
xfrm(a0), xfrm(a0.Plus(da)), xfrm(b0), xfrm(b0.Plus(db)), xfrm(ref),
|
||||||
xfrm(ref), c->Label());
|
xfrm(ref), c->Label(), c->GetStyle());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Constraint::COMMENT: {
|
case Constraint::COMMENT: {
|
||||||
Style *st = Style::Get(c->disp.style);
|
Style *st = SK.style.FindById(c->GetStyle());
|
||||||
writeText(xfrm(c->disp.offset), c->Label(),
|
writeText(xfrm(c->disp.offset), c->Label(),
|
||||||
Style::TextHeight(c->disp.style) / SS.GW.scale,
|
Style::TextHeight(c->GetStyle()) / SS.GW.scale,
|
||||||
st->textAngle, st->textOrigin);
|
st->textAngle, st->textOrigin, c->GetStyle());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,16 +402,35 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int findDxfColor(const RgbaColor &src) {
|
||||||
|
int best = 0;
|
||||||
|
double minDist = VERY_POSITIVE;
|
||||||
|
Vector srcv = Vector::From(src.redF(), src.greenF(), src.blueF());
|
||||||
|
for(int i = 1; i < 256; i++) {
|
||||||
|
RgbaColor dst = RGBi(DRW::dxfColors[i][0], DRW::dxfColors[i][1], DRW::dxfColors[i][2]);
|
||||||
|
Vector dstv = Vector::From(dst.redF(), dst.greenF(), dst.blueF());
|
||||||
|
double dist = srcv.Minus(dstv).Magnitude();
|
||||||
|
if(dist < minDist || best == 0) {
|
||||||
|
best = i;
|
||||||
|
minDist = dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
void assignEntityDefaults(DRW_Entity *entity, hStyle hs) {
|
void assignEntityDefaults(DRW_Entity *entity, hStyle hs) {
|
||||||
Style *s = Style::Get(hs);
|
Style *s = Style::Get(hs);
|
||||||
entity->color24 = s->Color(hs, true).ToPackedIntBGRA();
|
RgbaColor color = s->Color(hs, true);
|
||||||
|
entity->color24 = color.ToPackedIntBGRA();
|
||||||
|
entity->color = findDxfColor(color);
|
||||||
entity->layer = s->DescriptionString();
|
entity->layer = s->DescriptionString();
|
||||||
entity->lineType = DxfFileWriter::lineTypeName(s->stippleType);
|
entity->lineType = DxfFileWriter::lineTypeName(s->stippleType);
|
||||||
entity->ltypeScale = Style::StippleScaleMm(s->h);
|
entity->ltypeScale = Style::StippleScaleMm(s->h);
|
||||||
entity->setWidthMm(Style::WidthMm(hs.v));
|
entity->setWidthMm(Style::WidthMm(hs.v));
|
||||||
}
|
}
|
||||||
|
|
||||||
void assignDimensionDefaults(DRW_Dimension *dimension) {
|
void assignDimensionDefaults(DRW_Dimension *dimension, hStyle hs) {
|
||||||
|
assignEntityDefaults(dimension, hs);
|
||||||
dimension->layer = "dimensions";
|
dimension->layer = "dimensions";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,9 +540,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeAlignedDimension(Vector def1, Vector def2, Vector dimp,
|
void writeAlignedDimension(Vector def1, Vector def2, Vector dimp,
|
||||||
Vector textp, const std::string &text) {
|
Vector textp, const std::string &text, hStyle hs) {
|
||||||
DRW_DimAligned dim;
|
DRW_DimAligned dim;
|
||||||
assignDimensionDefaults(&dim);
|
assignDimensionDefaults(&dim, hs);
|
||||||
dim.setDef1Point(toCoord(def1));
|
dim.setDef1Point(toCoord(def1));
|
||||||
dim.setDef2Point(toCoord(def2));
|
dim.setDef2Point(toCoord(def2));
|
||||||
dim.setDimPoint(toCoord(dimp));
|
dim.setDimPoint(toCoord(dimp));
|
||||||
|
@ -534,9 +553,9 @@ public:
|
||||||
|
|
||||||
void writeLinearDimension(Vector def1, Vector def2, Vector dimp,
|
void writeLinearDimension(Vector def1, Vector def2, Vector dimp,
|
||||||
Vector textp, const std::string &text,
|
Vector textp, const std::string &text,
|
||||||
double angle, double oblique) {
|
double angle, double oblique, hStyle hs) {
|
||||||
DRW_DimLinear dim;
|
DRW_DimLinear dim;
|
||||||
assignDimensionDefaults(&dim);
|
assignDimensionDefaults(&dim, hs);
|
||||||
dim.setDef1Point(toCoord(def1));
|
dim.setDef1Point(toCoord(def1));
|
||||||
dim.setDef2Point(toCoord(def2));
|
dim.setDef2Point(toCoord(def2));
|
||||||
dim.setDimPoint(toCoord(dimp));
|
dim.setDimPoint(toCoord(dimp));
|
||||||
|
@ -548,9 +567,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeRadialDimension(Vector center, Vector radius,
|
void writeRadialDimension(Vector center, Vector radius,
|
||||||
Vector textp, const std::string &text) {
|
Vector textp, const std::string &text, hStyle hs) {
|
||||||
DRW_DimRadial dim;
|
DRW_DimRadial dim;
|
||||||
assignDimensionDefaults(&dim);
|
assignDimensionDefaults(&dim, hs);
|
||||||
dim.setCenterPoint(toCoord(center));
|
dim.setCenterPoint(toCoord(center));
|
||||||
dim.setDiameterPoint(toCoord(radius));
|
dim.setDiameterPoint(toCoord(radius));
|
||||||
dim.setTextPoint(toCoord(textp));
|
dim.setTextPoint(toCoord(textp));
|
||||||
|
@ -559,9 +578,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeDiametricDimension(Vector def1, Vector def2,
|
void writeDiametricDimension(Vector def1, Vector def2,
|
||||||
Vector textp, const std::string &text) {
|
Vector textp, const std::string &text, hStyle hs) {
|
||||||
DRW_DimDiametric dim;
|
DRW_DimDiametric dim;
|
||||||
assignDimensionDefaults(&dim);
|
assignDimensionDefaults(&dim, hs);
|
||||||
dim.setDiameter1Point(toCoord(def1));
|
dim.setDiameter1Point(toCoord(def1));
|
||||||
dim.setDiameter2Point(toCoord(def2));
|
dim.setDiameter2Point(toCoord(def2));
|
||||||
dim.setTextPoint(toCoord(textp));
|
dim.setTextPoint(toCoord(textp));
|
||||||
|
@ -570,9 +589,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeAngularDimension(Vector fl1, Vector fl2, Vector sl1, Vector sl2, Vector dimp,
|
void writeAngularDimension(Vector fl1, Vector fl2, Vector sl1, Vector sl2, Vector dimp,
|
||||||
Vector textp, const std::string &text) {
|
Vector textp, const std::string &text, hStyle hs) {
|
||||||
DRW_DimAngular dim;
|
DRW_DimAngular dim;
|
||||||
assignDimensionDefaults(&dim);
|
assignDimensionDefaults(&dim, hs);
|
||||||
dim.setFirstLine1(toCoord(fl1));
|
dim.setFirstLine1(toCoord(fl1));
|
||||||
dim.setFirstLine2(toCoord(fl2));
|
dim.setFirstLine2(toCoord(fl2));
|
||||||
dim.setSecondLine1(toCoord(sl1));
|
dim.setSecondLine1(toCoord(sl1));
|
||||||
|
@ -584,8 +603,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeText(Vector textp, const std::string &text,
|
void writeText(Vector textp, const std::string &text,
|
||||||
double height, double angle, int origin) {
|
double height, double angle, int origin, hStyle hs) {
|
||||||
DRW_Text txt;
|
DRW_Text txt;
|
||||||
|
assignEntityDefaults(&txt, hs);
|
||||||
txt.layer = "text";
|
txt.layer = "text";
|
||||||
txt.style = "unicode";
|
txt.style = "unicode";
|
||||||
txt.basePoint = toCoord(textp);
|
txt.basePoint = toCoord(textp);
|
||||||
|
|
|
@ -790,8 +790,7 @@ void GraphicsWindow::MouseRightUp(double x, double y) {
|
||||||
} else if(gs.points == 1) {
|
} else if(gs.points == 1) {
|
||||||
hs = Style::ForEntity(gs.point[0]);
|
hs = Style::ForEntity(gs.point[0]);
|
||||||
} else if(gs.constraints == 1) {
|
} else if(gs.constraints == 1) {
|
||||||
hs = SK.GetConstraint(gs.constraint[0])->disp.style;
|
hs = SK.GetConstraint(gs.constraint[0])->GetStyle();
|
||||||
if(!hs.v) hs.v = Style::CONSTRAINT;
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ class hEquation;
|
||||||
class Entity;
|
class Entity;
|
||||||
class Param;
|
class Param;
|
||||||
class Equation;
|
class Equation;
|
||||||
|
class Style;
|
||||||
|
|
||||||
|
|
||||||
// All of the hWhatever handles are a 32-bit ID, that is used to represent
|
// All of the hWhatever handles are a 32-bit ID, that is used to represent
|
||||||
|
@ -685,6 +686,7 @@ public:
|
||||||
void Draw(void);
|
void Draw(void);
|
||||||
void GetEdges(SEdgeList *sel);
|
void GetEdges(SEdgeList *sel);
|
||||||
bool IsStylable();
|
bool IsStylable();
|
||||||
|
hStyle GetStyle() const;
|
||||||
bool HasLabel();
|
bool HasLabel();
|
||||||
|
|
||||||
void LineDrawOrGetDistance(Vector a, Vector b);
|
void LineDrawOrGetDistance(Vector a, Vector b);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user