Code Monkey home page Code Monkey logo

c-pcb's Introduction

C-PCB

C++14 PCB router and solver.

Requires the glfw3 libs to be installed if you wish to build the viewer application.

Build everything with:

make -j

Build just the parts you need with:

make -j [c_pcb c_pcb_dsn c_pcb_view]

Example command lines would be:

./c_pcb --v 1 netlist.pcb | ./c_pcb_view --o 1 --s 7
./c_pcb_dsn test1.dsn | ./c_pcb --v 2 --z 1 --q 4 --r 1 | ./c_pcb_view --s 12

You can drop the output to a file and view it as an animation with:

./c_pcb --v 1 netlist.pcb > anim
./c_pcb_view anim

-h or --help for help on either app.

Format of .pcb input file or stdin follows, stdout format is identical:

DIMS : (double:width double:height double:depth)
POINT2D : (double:x double:y)
POINT3D : (double:x double:y double:z)
SHAPE : (POINT2D ...)
PATH : (POINT3D ...)
PATHS : ([PATH ...])
PAD : (double:pad_radius double:pad_gap POINT3D SHAPE)
PADS : ([PAD ...])
TRACK : (string:id double:track_radius double:via_radius double:track_gap PADS PATHS)
PCB : DIMS TRACK ... ... ()

Any character before an opening ( will be ignored, so comments can be freely added at any point the parser is looking for an opening (. Such comments are allowed in the input but will not be present in the output.

All track paths are assumed to have rounded ends and corners when testing for collision gap clearance. If the resulting board is milled or etched with beveled or square corners problems may occur in densely packed areas !

All the x, y, z co-ordinates of the board components MUST reside in the posative space ! Relative co-ordinates for SHAPE of pads will of course contain negative members, but the resulting value once added to the PAD position MUST be positive.

Special treatment is given to tracks with a track_radius of 0.0, they are used to hold unused pads and keepout paths. No attempt is made to route them, they are just added to the collision hash for all other routing. PADS can be empty as well as PATHS.

Tracks containing paths as input to the router are treated as pre existing wiring and are preserved as is in the output. Only pads of tracks with no existing wiring to them are routed.

DIMS : (double:width double:height double:depth)

Dimensions of the board in units and layers. depth is a double format but always has a fractional part of 0.

eg.

(100.0 50.0 2.0)

POINT2D : (double:x double:y)

2D point in units.

eg.

(56.7 24.3)

POINT3D : (double:x double:y double:z)

3D point in units and layer. z layer is a double format but always has a fractional part of 0. Layers are numbered from 0.

eg.

(56.7 24.3 0.0)
(50.7 25.3 1.0)

SHAPE : (POINT2D ...)

2D shape specified in relative units. These shapes are used to represent pad polygons, and are specified as closed polygons, the viewer fills these with a fan fill. An empty shape is used to signify a circular pad with radius of pad_radius. Two points are used to indicate an oval pad using the two points and the pad_radius. 3 or more points are a polygon shape for the pad.

eg.

circle -> ()
oval -> ((-20.0 0.0) (20.0 0.0))
square -> ((-5.0 -5.0) (-5.0 5.0) (5.0 5.0) (5.0 -5.0) (-5.0 -5.0))

PATH : (POINT3D ...)

A connected set of points on the PCB. Used to specify a section of a track or keepout. Transitions between layers must only be vertical through the layers and signify a through via in that position. All vias are through vias, there are no blind vias.

eg.

((10.0 10.0 0.0) (20.0 5.0 0.0) (20.0 5.0 1.0) (30.0 10.0 1.0) (40.0 10.0 1.0))

PATHS : ([PATH ...])

A set of path sections electrically connected with each other, normally via the pad terminals of components. Each track has a set of paths that are used to create the collision hash for that track. Paths data present in the input signify existing pre wiring for this track or keepout, and is retain unchanged by the router while it fills in any remaining connections.

PAD : (double:pad_radius double:pad_gap POINT3D SHAPE)

A single pad of a component. pads_radius is 0.0 if the pad shape is not a circle or oval. pad_gap is the collision gap required by the pad in units. The POINT3D is the position of the pad on the board and then the SHAPE is relative to that position.

PADS : ([PAD ...])

Represents all the electrically connected component pads of a track. A padstack should be grouped together rather than being spread throughout the pads data. This is because the router looks for a sequence of pads with matching x and y position and uses the z min and max to create grid deformation information for neck down.

TRACK : (string:id double:track_radius double:via_radius double:track_gap PADS PATHS)

A set of electrically connected component pads and paths, or unused pads and keepouts. track_radius in units for the radius of all tracks, via_radius for the radius of all vias within this track and track_gap for the required gap between the tracks and vias of this track any other components on the PCB. track_radius of 0.0 specifies unused pads and or keepouts.

The id is just a user supplied track identifier that is unchanged from the input to output, as the order of tracks in the output may be changed due to the routing process. This allows the identification or sorting of the output by the output consumer process etc.

C_PCB options

-t:  timeout in seconds, default 600
-v:  verbosity level 0..1, default 0
-z:  vias cost, 0..100, default 0
-s:  number of samples, default 1
-r:  grid resolution 1..4, default 1
-q:  area quantization, default 1
-fr: flood range 1..5, default 2
-xr: even layer x range 0..5, default 1
-yr: odd layer y range 0..5, default 1

More screenshots

c-pcb's People

Contributors

vygr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

c-pcb's Issues

Unmatched \" quote defined key word STRING_QUOTE. May has potentially parsing error.s.

-----.dsn------------------------------------------------------------------------------
(string_quote ")
(space_in_quoted_tokens on)
(host_cad "KiCad's Pcbnew")

---result below ------------------------------------------------------------------------
pcb
D:\pdavies\Documents\KiCad\wetroom-shield\wetroom-shield.dsn
parser
string_quote
)
(space_in_quoted_tokens on)
(host_cad
KiCad's
Pcbnew"
host_version
(2013-07-07 BZR 4022)-stable

--- fixed ----------------------------------------------------------------------
pcb
D:\pdavies\Documents\KiCad\wetroom-shield\wetroom-shield.dsn
parser
string_quote
"
space_in_quoted_tokens
on
host_cad
KiCad's Pcbnew
host_version
(2013-07-07 BZR 4022)-stable
----solution-------------------------------------------------------------------
It is better to treat the value of string_quote as a string identifier. Of course, we can also use a temporary solution to check whether the current node is a string_quote when encountering ("), and not treat it as a string.

-- code ----------------------------------------------------------------------
c_pcb_dsn.cpp:read_tree

if (b == '"')
		{
			if(nodeName != "string_quote")
			{
				in.get(c);
				t.m_branches.push_back(read_quoted_string(in));
				in.get(c);
				continue;
			}
			else
			{
				in.get(c);
				std::string str;
				str.push_back(b);
				t.m_branches.push_back(tree{str, {}});

				continue;
			}
		}

Thread 1 "view" received signal SIGSEGV, Segmentation fault.

Compiles without error BUT view gives a SIGSEGV Segmentation fault. The "PCB Viewer" window opens (blank) and then there is the SIGSEGV.

Below is a gdb backtrace of the problem. Any ideas?

ecomer@asrock C-PCB]$ cat /proc/version
Linux version 4.14.34-1-MANJARO (builduser@development) (gcc version 7.3.1 20180312 (GCC)) #1 SMP PREEMPT Thu Apr 12 17:26:43 UTC 2018
[ecomer@asrock C-PCB]$ ./dsn2pcb test1.dsn | ./pcb --v 1 --z 8 --q 10 --r 2 >x
Number of terminals: 204
Number of Nets: 55
Number of Vias: 51
Number of terminals: 204
Number of Nets: 55
Number of Vias: 51
[ecomer@asrock C-PCB]$ gdb ./view
GNU gdb (GDB) 8.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./view...done.
(gdb) r x
Starting program: /home/ecomer/src/C-PCB/view x
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7fffea1c9700 (LWP 910)]
[New Thread 0x7fffe918a700 (LWP 911)]
[New Thread 0x7fffe8989700 (LWP 912)]
[New Thread 0x7fffdbfff700 (LWP 913)]
[New Thread 0x7fffdb7fe700 (LWP 914)]

Thread 1 "view" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x000055555555755d in main (argc=2, argv=0x7fffffffdff8) at view.cpp:452
(gdb) 

integration to QautoRouter

Hi
this project is a very nice project, it help a lot with autorouter for PCB, but many users doesn't use it directly because it only works at command line mode, and it isn't a installation package application.
if anyone can help to integration as QautoRouter plugin to run, I think this project will be more public and helpful, it maybe will more active and popular than Freerouting

https://github.com/udif/qautorouter-svn
https://sourceforge.net/projects/qautorouter/

but sadly, the Qautorouter doesn't maintain anymore, it is a bad news.

thank you for sharing, it is a nice work. :)

Potential lifetime issue with net(s)

net holds a pointer to pcb

In c_pcb.cpp best_pcb is copy-constructed from current_pcb. Should current_pcb go out of scope, best_pcb would become compromised and result in segfaults when calling methods which would require the net-s it contains to refer to the pcb pointers inside them, as the pcb pointers are always pointing to current_pcb. While this works the way it is used, this architecture is brittle and unintuitive. I would suggest implementing a copy-constructor for pcb which would correctly update nets to contain pointers to the new instance. Hope this is intelligible.

How to Determine Via Locations?

Hello, I am doing research on PCB wiring recently, can you share your algorithm or ideas on how to determine the location of vias on a multi-layer PCB? Thank you

Segement Fault in c_pcb_View:main() 326:glGenVertexArrays()

Env:
Ubuntu18.04, vmware
OpenGL version string: 3.3 (Compatibility Profile) Mesa 20.0.8

Error:
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000000000000000 in ?? ()

solve:
start GLEW extension handler after glfwMakeContextCurrent(window) called;
such as:

        auto window = glfwCreateWindow(width, height, "PCB Viewer", NULL, NULL);
	if (!window)
	{
		glfwTerminate();
		exit(EXIT_FAILURE);
	}
	glfwMakeContextCurrent(window);

	    // start GLEW extension handler huangli  add successful
  	√ glewExperimental = GL_TRUE;
  	√ glewInit();

         glfwSetKeyCallback(window, key_callback); 
         ```
    

about extern function of mymath.cpp error

hi, vygr!

I encountered some problems when running the c++ program, I don't know how to solve it, I would like to ask you。

c_pcb.cpp and c_pcb_dsn.cpp could be compiled and got c_pcb.exe and c_pcb_dsn, but c_pcb_view.cpp had some error.

Since I don't know how to add the glfw library to the Makefile, I use the cmakelists file to perform cmake first, then make.
the errors are the compiler cannot resolve the related functions in mymath.cpp.

The file content of cmakefilelists is:
image

I'm not very good at c++, hope you can help me take a look, thanks!
errors about:
image

Link to glew

On Ubuntu 16.04 I need to add a a link to libglew.

clang++ -O2 --std=c++14 pkg-config --cflags glfw3 view.cpp mymath.cpp -oview pkg-config --static --libs glfw3 glew

Clarify Input and Output Formats

Hi! This looks really great, do you think you can clarify the file types for input and output? Are the .dsn Specctra Netlists? What about the .pcb formats? Proteus?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.