Skip to content

Commit

Permalink
Start trying to replicate the TNP
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFerraro committed Apr 16, 2024
1 parent 2ca52f6 commit dbca326
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 2 deletions.
83 changes: 81 additions & 2 deletions packages/cadmium/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,88 @@ use truck_polymesh::{obj, InnerSpace, Invertible, ParametricSurface, Tolerance};
use truck_shapeops::{and, or, ShapeOpsCurve, ShapeOpsSurface};
use truck_topology::{Shell, Solid};

// use oplog::Operation;

fn main() {
topological_naming();
}

fn topological_naming() {
// Let's replicate the flow seen here: https://wiki.freecad.org/Topological_naming_problem
let mut el = EvolutionLog::new();

// Create the Top Plane
let top_plane_id = el.append(Operation::CreatePlane {
nonce: "the top plane".to_string(),
});
el.append(Operation::SetPlaneName {
plane_id: top_plane_id.clone(),
name: "Top".to_string(),
});
let set_plane = el.append(Operation::SetPlane {
plane_id: top_plane_id.clone(),
plane: Plane::top(),
});

let sketch_id = el.append(Operation::CreateSketch {
nonce: "top sketch".to_string(),
});
el.append(Operation::SetSketchName {
sketch_id: sketch_id.clone(),
name: "Sketch1".to_string(),
});
el.append(Operation::SetSketchPlane {
sketch_id: sketch_id.clone(),
plane_id: top_plane_id.clone(),
});

// Create the base "L" shape
// autojoin means "look for the nearest endpoints and join them if they're close enough"
el.append(Operation::AddSketchLine {
sketch_id: sketch_id.clone(),
start: (0.0, 0.0),
end: (0.0, 100.0),
});
el.append(Operation::AddSketchLine {
sketch_id: sketch_id.clone(),
start: (0.0, 100.0),
end: (50.0, 100.0),
});
el.append(Operation::AddSketchLine {
sketch_id: sketch_id.clone(),
start: (50.0, 100.0),
end: (50.0, 50.0),
});
el.append(Operation::AddSketchLine {
sketch_id: sketch_id.clone(),
start: (50.0, 50.0),
end: (100.0, 50.0),
});
el.append(Operation::AddSketchLine {
sketch_id: sketch_id.clone(),
start: (100.0, 50.0),
end: (100.0, 0.0),
});
el.append(Operation::AddSketchLine {
sketch_id: sketch_id.clone(),
start: (100.0, 0.0),
end: (0.0, 0.0),
});

let extrusion_id = el.append(Operation::CreateExtrusion {
nonce: "top extrusion".to_string(),
});
el.append(Operation::SetExtrusionName {
extrusion_id: extrusion_id.clone(),
name: "Extrude1".to_string(),
});
el.append(Operation::SetExtrusionSketch {
extrusion_id: extrusion_id.clone(),
sketch_id: sketch_id.clone(),
});

el.git_log();
}

fn main_good() {
let mut el = EvolutionLog::new();

// Create the Top Plane
Expand Down
22 changes: 22 additions & 0 deletions packages/cadmium/src/oplog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ pub enum Operation {
y: f64,
radius: f64,
},
AddSketchLine {
sketch_id: Sha,
start: (f64, f64),
end: (f64, f64),
},

CreateExtrusion {
nonce: String,
Expand Down Expand Up @@ -391,6 +396,11 @@ impl Operation {
y,
radius,
} => hasher.update(format!("{sketch_id}-{x}-{y}-{radius}").as_bytes()),
Operation::AddSketchLine {
sketch_id,
start,
end,
} => hasher.update(format!("{sketch_id}-{start:?}-{end:?}").as_bytes()),
Operation::CreateExtrusion { nonce } => hasher.update(format!("{nonce}").as_bytes()),
Operation::SetExtrusionName { extrusion_id, name } => {
hasher.update(format!("{extrusion_id}-{name}").as_bytes())
Expand Down Expand Up @@ -495,6 +505,18 @@ impl Operation {
y,
radius
),
Operation::AddSketchLine {
sketch_id,
start,
end,
} => format!(
"AddSketchLine: {} ({}, {}) to ({}, {})",
sketch_id.to_owned()[..num_chars].to_string(),
start.0,
start.1,
end.0,
end.1
),
Operation::CreateExtrusion { nonce } => format!("CreateExtrusion: {}", nonce),
Operation::SetExtrusionName { extrusion_id, name } => {
format!(
Expand Down

0 comments on commit dbca326

Please sign in to comment.