fix(color): show color book identity

This commit is contained in:
Hakan Seven committed 2026-09-01 08:44:28 +03:00
1 parent 7ea4f338f6
commit 6d6defa0ad
19 files changed
+142 -30

No files matched your search

+1
View File
@@ -2466,6 +2466,7 @@ impl OpenCADStudio {
dst_common.linetype_handle = common.linetype_handle;
dst_common.linetype_scale = common.linetype_scale;
dst_common.transparency = common.transparency.clone();
dst_common.color_name = common.color_name.clone();
dst_common.color_book_handle = common.color_book_handle;
dst_common.full_visual_style_handle =
common.full_visual_style_handle;
+2
View File
@@ -128,6 +128,8 @@ impl OpenCADStudio {
if let Some(l) = self.tabs[i].scene.document.layers.get_mut(&layer_name)
{
l.color = acadrust::types::Color::from_index(idx);
l.color_name = None;
l.book_name = None;
self.push_undo_snapshot(i, "LAYER COLOR");
self.tabs[i].dirty = true;
// By-layer colour is baked into every wire on
+4
View File
@@ -616,6 +616,8 @@ impl OpenCADStudio {
}
"COLOR" => {
common.color = color_val.unwrap();
common.color_name = None;
common.color_book_handle = None;
changed += 1;
}
"TRANSPARENCY" => {
@@ -661,6 +663,8 @@ impl OpenCADStudio {
if let Some(entity) = self.tabs[i].scene.document.get_entity_mut(*handle) {
let common = entity.common_mut();
common.color = acadrust::types::Color::ByLayer;
common.color_name = None;
common.color_book_handle = None;
common.linetype = "ByLayer".to_string();
common.line_weight = acadrust::types::LineWeight::ByLayer;
changed += 1;
+48 -19
View File
@@ -509,37 +509,59 @@ impl OpenCADStudio {
{
let doc = &self.tabs[i].scene.document;
let common = entity.common();
if let Some(acadrust::objects::ObjectType::BookColor(book)) = common
let named_color = common
.color_book_handle
.filter(|handle| handle.is_valid())
.and_then(|handle| doc.objects.get(&handle))
{
.and_then(|object| match object {
acadrust::objects::ObjectType::BookColor(book) => Some((
book.color,
book.book_name.clone(),
book.color_name.clone(),
)),
_ => None,
})
.or_else(|| {
let identity = common.color_name.as_deref()?;
let (book_name, color_name) = identity
.split_once('$')
.map(|(book, color)| (book.to_string(), color.to_string()))
.unwrap_or_else(|| (String::new(), identity.to_string()));
Some((common.color, book_name, color_name))
});
if let Some((color, book_name, color_name)) = named_color {
for section in sections.iter_mut() {
if let Some(row) =
section.props.iter_mut().find(|row| row.field == "color")
{
row.value =
crate::scene::model::object::PropValue::ColorChoice(
book.color,
);
row.value = crate::scene::model::object::PropValue::NamedColorChoice {
color,
name: color_name.clone(),
};
}
}
use crate::entities::common::ro_prop;
let mut props = Vec::new();
if !book_name.is_empty() {
props.push(ro_prop(
t!("Book").as_ref(),
"book_color_book",
book_name,
));
}
props.push(ro_prop(
t!("Color Name").as_ref(),
"book_color_name",
color_name,
));
props.push(ro_prop(
t!("Color").as_ref(),
"book_color_value",
format!("{:?}", color),
));
sections.push(crate::scene::model::object::PropSection {
title: t!("Color Book").into_owned(),
props: vec![
ro_prop(t!("Book").as_ref(), "book_color_book", book.book_name.clone()),
ro_prop(
t!("Color Name").as_ref(),
"book_color_name",
book.color_name.clone(),
),
ro_prop(
t!("Color").as_ref(),
"book_color_value",
format!("{:?}", book.color),
),
],
props,
});
}
@@ -2916,6 +2938,7 @@ fn make_sections_read_only(
acadrust::types::Color::Index(index) => index.to_string(),
acadrust::types::Color::Rgb { r, g, b } => format!("{r},{g},{b}"),
},
PropValue::NamedColorChoice { name, .. } => name.clone(),
PropValue::ColorVaries
| PropValue::LwVaries
| PropValue::FieldLwVaries { .. } => VARIES_LABEL.to_string(),
@@ -3075,6 +3098,9 @@ fn merge_prop_value(
PropValue::LayerChoice(VARIES_LABEL.into())
}
(PropValue::ColorChoice(_), PropValue::ColorChoice(_))
| (PropValue::NamedColorChoice { .. }, PropValue::NamedColorChoice { .. })
| (PropValue::ColorChoice(_), PropValue::NamedColorChoice { .. })
| (PropValue::NamedColorChoice { .. }, PropValue::ColorChoice(_))
| (PropValue::ColorVaries, _)
| (_, PropValue::ColorVaries) => PropValue::ColorVaries,
(PropValue::LwChoice(_), PropValue::LwChoice(_))
@@ -3261,6 +3287,9 @@ fn update_row_color(
};
match &mut row.value {
PropValue::ColorChoice(current) => *current = color,
PropValue::NamedColorChoice { .. } => {
row.value = PropValue::ColorChoice(color)
}
PropValue::ReadOnly(current) => *current = label,
PropValue::ReadOnlyWithTooltip { value: current, .. } => *current = label,
_ => {}
+2
View File
@@ -3226,6 +3226,8 @@ fn apply_attr_row(a: &mut acadrust::entities::AttributeEntity, row: &AttrRow) ->
}
if a.common.color != row.color {
a.common.color = row.color;
a.common.color_name = None;
a.common.color_book_handle = None;
ch = true;
}
if a.common.linetype != row.linetype {
+4
View File
@@ -2633,11 +2633,15 @@ impl OpenCADStudio {
for name in &names {
if let Some(dl) = self.tabs[i].scene.document.layers.get_mut(name) {
dl.color = color;
dl.color_name = None;
dl.book_name = None;
}
}
for pl in self.tabs[i].layers.layers.iter_mut() {
if names.contains(&pl.name) {
pl.color = color;
pl.color_name = None;
pl.book_name = None;
}
}
self.tabs[i].dirty = true;