Skip to content

Commit f879641

Browse files
authored
Merge pull request #4 from olback/add_ecad_formats
add support for easyeda & kicad
2 parents 65c8de3 + b7d6777 commit f879641

File tree

8 files changed

+59
-15
lines changed

8 files changed

+59
-15
lines changed

cli.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ args:
2828
takes_value: true
2929
multiple: false
3030
conflicts_with:
31+
- input
3132
- id
3233
- generate
3334
- output:
@@ -58,10 +59,10 @@ args:
5859
# - designspark_pcb_pro
5960
# - diptrace
6061
- eagle
61-
# - easyeda
62+
- easyeda
6263
# - easy_pc
6364
# - ecadstar
64-
# - kicad
65+
- kicad
6566
# - orcad_allegro16
6667
# - pads
6768
# - proteus

src/cse.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ impl CSE {
115115

116116
match &self.config.settings.format {
117117
Format::EAGLE => format::eagle::Extractor::extract(&mut files, filename, &mut item)?,
118-
// ! NOTE: DO NOT ADD A _ => {} CATCHER HERE!
118+
Format::EASYEDA => format::easyeda::Extractor::extract(&mut files, filename, &mut item)?,
119+
Format::KICAD => format::kicad::Extractor::extract(&mut files, filename, &mut item)?,
119120
Format::ZIP => return Err(LLError::new("This should be unreachable!"))
121+
// ! NOTE: DO NOT ADD A _ => {} CATCHER HERE!
120122
};
121123

122124
}

src/format/eagle.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,8 @@ impl ExtractorTrait for Extractor {
66

77
fn extract<S: Into<String>>(files: &mut Files, file_path: S, item: &mut ZipFile) -> LLResult<()> {
88

9-
let fp = file_path.into();
9+
generic_extractor("eagle", files, file_path, item)
1010

11-
if fp.to_lowercase().contains("eagle") {
12-
let path = PathBuf::from(fp);
13-
let base_name = path.file_name().unwrap().to_string_lossy().to_string();
14-
let mut f_data = Vec::<u8>::new();
15-
item.read_to_end(&mut f_data)?;
16-
files.insert(base_name, f_data);
17-
}
18-
19-
Ok(())
2011
}
2112

2213
}

src/format/easyeda.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use super::extractor_prelude::*;
2+
3+
pub struct Extractor;
4+
5+
impl ExtractorTrait for Extractor {
6+
7+
fn extract<S: Into<String>>(files: &mut Files, file_path: S, item: &mut ZipFile) -> LLResult<()> {
8+
9+
generic_extractor("easyeda", files, file_path, item)
10+
11+
}
12+
13+
}

src/format/extractor_prelude.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@ pub(super) use std::{io::Read, path::PathBuf};
77
pub type Files = HashMap::<String, Vec<u8>>;
88

99
pub trait ExtractorTrait {
10-
fn extract<S: Into<String>>(files: &mut Files, filepath: S, file: &mut ZipFile) -> LLResult<()>;
10+
fn extract<S: Into<String>>(files: &mut Files, file_path: S, item: &mut ZipFile) -> LLResult<()>;
1111
}
1212

13+
pub(super) fn generic_extractor<S: Into<String>>(match_path: &str, files: &mut Files, file_path: S, item: &mut ZipFile) -> LLResult<()> {
1314

15+
let fp = file_path.into();
16+
17+
if fp.to_lowercase().contains(match_path) {
18+
let path = PathBuf::from(fp);
19+
let base_name = path.file_name().unwrap().to_string_lossy().to_string();
20+
let mut f_data = Vec::<u8>::new();
21+
item.read_to_end(&mut f_data)?;
22+
files.insert(base_name, f_data);
23+
}
24+
25+
Ok(())
26+
27+
}

src/format/kicad.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use super::extractor_prelude::*;
2+
3+
pub struct Extractor;
4+
5+
impl ExtractorTrait for Extractor {
6+
7+
fn extract<S: Into<String>>(files: &mut Files, file_path: S, item: &mut ZipFile) -> LLResult<()> {
8+
9+
generic_extractor("kicad", files, file_path, item)
10+
11+
}
12+
13+
}

src/format/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
pub mod eagle;
2+
pub mod easyeda;
3+
pub mod kicad;
24

35
pub(super) mod extractor_prelude;
46
pub use extractor_prelude::{
@@ -9,6 +11,8 @@ pub use extractor_prelude::{
911
#[derive(Debug, Clone, PartialEq)]
1012
pub enum Format {
1113
EAGLE,
14+
EASYEDA,
15+
KICAD,
1216
ZIP
1317
}
1418

@@ -20,6 +24,8 @@ impl Format {
2024

2125
match f.as_str() {
2226
"eagle" => Self::EAGLE,
27+
"easyeda" => Self::EASYEDA,
28+
"kicad" => Self::KICAD,
2329
"zip" => Self::ZIP,
2430
_ => {
2531
eprintln!("Unknown format. Defaulting to ZIP!");

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn real_main() -> LLResult<()> {
4848
Err(e) => Err(e)
4949
}
5050

51-
} else if conf.settings.watch_path.is_some() {
51+
} else if conf.settings.watch_path.is_some() && conf.input.is_empty() {
5252

5353
let p = conf.settings.watch_path.clone().unwrap();
5454
let mut w = Watcher::new(p, component_search_engine)?;
@@ -77,6 +77,10 @@ fn real_main() -> LLResult<()> {
7777

7878
} else {
7979

80+
if conf.settings.watch_path.is_some() {
81+
println!("Ignoring watch command since input was supplied");
82+
}
83+
8084
let e = match conf.treat_input_as_id {
8185
true => {
8286
Epw::from_id(conf.input.parse::<u32>()?)

0 commit comments

Comments
 (0)