first commit

This commit is contained in:
Hakan Seven committed 2026-03-22 14:56:27 +03:00
1 parent d52c6440ff
commit d2fdac7f1e
274 files changed
+89330

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub fn tool() -> ToolDef {
ToolDef {
id: "BOX",
label: "Box",
icon: IconKind::Glyph("⬜"),
event: ModuleEvent::Command("BOX".to_string()),
}
}
+9
View File
@@ -0,0 +1,9 @@
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub fn tool() -> ToolDef {
ToolDef {
id: "CLEAR",
label: "Clear",
icon: IconKind::Glyph("🗑"),
event: ModuleEvent::ClearModels,
}
}
+91
View File
@@ -0,0 +1,91 @@
use acadrust::Handle;
use glam::Vec3;
use crate::command::{CadCommand, CmdResult};
use crate::modules::{IconKind, ModuleEvent, ToolDef};
use crate::scene::wire_model::WireModel;
pub fn tool() -> ToolDef {
ToolDef {
id: "BLOCK",
label: "Create Block",
icon: IconKind::Svg(include_bytes!("../../../assets/icons/blocks/block.svg")),
event: ModuleEvent::Command("BLOCK".to_string()),
}
}
enum Step {
Name,
Base { name: String },
}
pub struct CreateBlockCommand {
handles: Vec<Handle>,
step: Step,
}
impl CreateBlockCommand {
pub fn new(handles: Vec<Handle>) -> Self {
Self {
handles,
step: Step::Name,
}
}
}
impl CadCommand for CreateBlockCommand {
fn name(&self) -> &'static str {
"BLOCK"
}
fn prompt(&self) -> String {
match &self.step {
Step::Name => format!(
"BLOCK Enter block name [{} objects selected]:",
self.handles.len()
),
Step::Base { name } => format!(
"BLOCK Specify base point for \"{}\" [{} objects]:",
name,
self.handles.len()
),
}
}
fn on_point(&mut self, pt: Vec3) -> CmdResult {
match &self.step {
Step::Name => CmdResult::NeedPoint,
Step::Base { name } => CmdResult::CreateBlock {
handles: self.handles.clone(),
name: name.clone(),
base: pt,
},
}
}
fn on_enter(&mut self) -> CmdResult {
CmdResult::Cancel
}
fn wants_text_input(&self) -> bool {
matches!(self.step, Step::Name)
}
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
if !matches!(self.step, Step::Name) {
return None;
}
let name = text.trim();
if name.is_empty() {
return None;
}
self.step = Step::Base {
name: name.to_string(),
};
Some(CmdResult::NeedPoint)
}
fn on_preview_wires(&mut self, _pt: Vec3) -> Vec<WireModel> {
vec![]
}
}
+9
View File
@@ -0,0 +1,9 @@
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub fn tool() -> ToolDef {
ToolDef {
id: "CYLINDER",
label: "Cylinder",
icon: IconKind::Glyph("⬡"),
event: ModuleEvent::Command("CYLINDER".to_string()),
}
}
+94
View File
@@ -0,0 +1,94 @@
use acadrust::entities::Insert;
use acadrust::types::Vector3;
use acadrust::EntityType;
use glam::Vec3;
use crate::command::{CadCommand, CmdResult};
use crate::modules::{IconKind, ModuleEvent, ToolDef};
use crate::scene::wire_model::WireModel;
pub fn tool() -> ToolDef {
ToolDef {
id: "INSERT",
label: "Insert Block",
icon: IconKind::Svg(include_bytes!("../../../assets/icons/blocks/insert.svg")),
event: ModuleEvent::Command("INSERT".to_string()),
}
}
enum Step {
Name,
Point { name: String },
}
pub struct InsertBlockCommand {
available: Vec<String>,
step: Step,
}
impl InsertBlockCommand {
pub fn new(available: Vec<String>) -> Self {
Self {
available,
step: Step::Name,
}
}
}
impl CadCommand for InsertBlockCommand {
fn name(&self) -> &'static str {
"INSERT"
}
fn prompt(&self) -> String {
match &self.step {
Step::Name => {
let hint = if self.available.is_empty() {
String::new()
} else {
format!(" [{}]", self.available.join(", "))
};
format!("INSERT Enter block name:{hint}")
}
Step::Point { name } => format!("INSERT Specify insertion point for \"{}\":", name),
}
}
fn on_point(&mut self, pt: Vec3) -> CmdResult {
match &self.step {
Step::Name => CmdResult::NeedPoint,
Step::Point { name } => {
CmdResult::CommitAndExit(EntityType::Insert(Insert::new(
name.clone(),
Vector3::new(pt.x as f64, pt.y as f64, pt.z as f64),
)))
}
}
}
fn on_enter(&mut self) -> CmdResult {
CmdResult::Cancel
}
fn wants_text_input(&self) -> bool {
matches!(self.step, Step::Name)
}
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
if !matches!(self.step, Step::Name) {
return None;
}
let name = text.trim();
if !self.available.iter().any(|candidate| candidate.eq_ignore_ascii_case(name)) {
return None;
}
self.step = Step::Point {
name: name.to_string(),
};
Some(CmdResult::NeedPoint)
}
fn on_preview_wires(&mut self, _pt: Vec3) -> Vec<WireModel> {
vec![]
}
}
+43
View File
@@ -0,0 +1,43 @@
// Insert module — file import, solid primitives, and blocks.
mod box_prim;
mod clear;
pub(crate) mod create_block;
mod cylinder;
pub(crate) mod insert_block;
mod open_obj;
mod sphere;
use crate::modules::{CadModule, RibbonGroup};
pub struct InsertModule;
impl CadModule for InsertModule {
fn id(&self) -> &'static str {
"insert"
}
fn title(&self) -> &'static str {
"Insert"
}
fn ribbon_groups(&self) -> Vec<RibbonGroup> {
vec![
RibbonGroup {
title: "Import",
tools: vec![open_obj::tool().into(), clear::tool().into()],
},
RibbonGroup {
title: "Primitives",
tools: vec![
box_prim::tool().into(),
sphere::tool().into(),
cylinder::tool().into(),
],
},
RibbonGroup {
title: "Block",
tools: vec![create_block::tool().into(), insert_block::tool().into()],
},
]
}
}
+9
View File
@@ -0,0 +1,9 @@
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub fn tool() -> ToolDef {
ToolDef {
id: "OPEN",
label: "Open",
icon: IconKind::Glyph("📂"),
event: ModuleEvent::OpenFileDialog,
}
}
+9
View File
@@ -0,0 +1,9 @@
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub fn tool() -> ToolDef {
ToolDef {
id: "SPHERE",
label: "Sphere",
icon: IconKind::Glyph("⬤"),
event: ModuleEvent::Command("SPHERE".to_string()),
}
}