Recent

Author Topic: [Tips] Circuit Simulator  (Read 6655 times)

metallaro1980

  • New Member
  • *
  • Posts: 38
[Tips] Circuit Simulator
« on: July 26, 2019, 10:59:42 am »
I would like to try to develop an electronics program.
The program saves all the information of the circuit components (including the x and y coordinates) in a sch file.
Including all connections.
When viewing, the program should be able to display the circuit in a white window inside a TForm.
Within this white window the program must be able to display the circuit components in the form of dynamic vector objects (a resistance in the form of a rectangular box with two lines) created at runtime.
Most likely I would use ngspice as a simulator.
I don't have to manipulate dxf and other vector graphics files.
I just need a library that allows me to create vector objects inside a white window with lines (connections), points (nodes) etc.
Which library do you recommend to use for these dynamic vector objects?

best regards
Andrea Verdi

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1225
    • Burdjia
Re: [Tips] Circuit Simulator
« Reply #1 on: July 26, 2019, 11:49:13 am »
I don't know an specific library, but you can find lists with them in the wiki:
I hope this helps.
« Last Edit: August 28, 2019, 01:17:37 pm by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

simone

  • Hero Member
  • *****
  • Posts: 706
Re: [Tips] Circuit Simulator
« Reply #2 on: July 26, 2019, 12:54:14 pm »
For a similar task I'm using EvsSimpleGraph component:
 
https://github.com/taazz/EvsSimpleGraph

It is available also via Online Package Manager. In this way you can add it in the
'misc' tab and use as design time component.

It is a porting of the following component developed for Delphi:

http://www.delphiarea.com/products/delphi-components/simplegraph/
Microsoft Windows 10/11 64 bit - Lazarus 4.8/4.6 FPC 3.2.2 x86_64-win64-win32/win64

Edson

  • Hero Member
  • *****
  • Posts: 1330
Re: [Tips] Circuit Simulator
« Reply #3 on: July 26, 2019, 11:18:22 pm »
I have developed a library for that: https://github.com/t-edson/ogEditGraf

It's not so complete, but have the basic classes to manage graphic objects in screen (Zoom, pan, scroll, conectors).

I've used it in my PIC debugger/simulator https://github.com/t-edson/PicPas
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

metallaro1980

  • New Member
  • *
  • Posts: 38
Re: [Tips] Circuit Simulator
« Reply #4 on: July 29, 2019, 03:04:00 pm »
for now my programs works....but you had to enter the nodes...   :-\

Edson

  • Hero Member
  • *****
  • Posts: 1330
Re: [Tips] Circuit Simulator
« Reply #5 on: July 30, 2019, 02:20:18 am »
I see you are using my library ogEditGraf. I recommend to disable some control points (sizing points) in the resistor objects because they are too crowded in the small shape.

Also you could implement some grid to adjust the object positions.

The connectors can be smarter than simple lines but you have to program the behaviour and view.

Do you have your project published in GitHub?
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

avra

  • Hero Member
  • *****
  • Posts: 2596
    • Additional info
Re: [Tips] Circuit Simulator
« Reply #6 on: July 30, 2019, 08:13:12 am »
Do connector lines have to be straight as in the screenshot, or they can be horizontal and vertical, following shortest path and doing only 90 degree turns when needed? Os some sort of splines like in node-red?
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

metallaro1980

  • New Member
  • *
  • Posts: 38
Re: [Tips] Circuit Simulator
« Reply #7 on: July 30, 2019, 04:00:09 pm »
connector for now are straight as in the screenshot...
i'm doing virtual multimeter now (voltage between two seletected node)
after i will doing some embellishments

metallaro1980

  • New Member
  • *
  • Posts: 38
Re: [Tips] Circuit Simulator
« Reply #8 on: August 24, 2019, 06:48:13 pm »
the project is going well (about 31000 lines of code) I have a problem save circuit to an image.
I put the paintbox inside a scrollbox. when the image dimensions of the circuit exceed the standard size and I decide to save as image the image are not correct.
in the exported image i can see also some parts of the main form
Code: Pascal  [Select][+][-]
  1. procedure TForm1.MenuItem45Click(Sender: TObject);
  2. var Jpeg: TJpegImage;
  3. var Source: TRect;
  4. var Dest: TRect;
  5. var FilePathCircuitJPG : string;
  6. var w,h : int64;
  7. begin
  8.   if (motedi.objetos.count = 0) then exit;
  9.   savedialog2.Filter:= 'Jpeg images|*.jpeg;*.jpg';
  10.   if (savedialog2.Execute ) then
  11.   begin
  12.     if (savedialog2.FileName = '') then exit;
  13.     FilePathCircuitJPG := savedialog2.FileName;
  14.     Jpeg := TJpegImage.Create;
  15.     try
  16.       with Jpeg do
  17.       begin
  18.         w := PaintBox1.Width;
  19.         h := PaintBox1.Height;
  20.         Dest := Rect(0, 0, w, h);
  21.       end;
  22.       Jpeg.SetSize(w,h);
  23.       with PaintBox1 do
  24.         Source := Rect(0, 0, w, h);
  25.         Jpeg.Canvas.CopyRect(Dest,  PaintBox1.Canvas, Source);
  26.         Jpeg.SaveToFile(FilePathCircuitJPG);
  27.  
  28.     finally
  29.       Jpeg.Free;
  30.     end;
  31.  
  32.   end;
  33.  
  34.  
  35. end;  
how can i fix it? thanks
« Last Edit: August 24, 2019, 06:53:35 pm by metallaro1980 »

jamie

  • Hero Member
  • *****
  • Posts: 7891
Re: [Tips] Circuit Simulator
« Reply #9 on: August 24, 2019, 07:03:32 pm »
That really isn't the way to do it.

 I assume you have all the code needed in the Onpaint handler of the scrollbox to show your circuit image ?

 What you need to do is pass a canvas to that code instead of assuming its always the ScrollBox canvas so that you can select where to paint the surface to..

 So basically write yourself a master procedure that updates the scrollbox area accecpting a Canvas as a parameter. When the Onpaint for the scrollBox is triggered then simply call this function passing its Canvas to it, when you want to create a Jpeg, pass the canvas of the jpeg to it instead or a Bitmap that can be converted to a jpg afterwards.

 This way you have one master function that prints the circuit using a canvas to send it to and there will be no limit on size, at least there shouldn't be..


 I think you get the picture.
The only true wisdom is knowing you know nothing

metallaro1980

  • New Member
  • *
  • Posts: 38
Re: [Tips] Circuit Simulator
« Reply #10 on: October 03, 2019, 03:12:26 pm »
i don't understand why lazarus does not change the icon in the bar...
the icon on the other forms are right but not the icon on the bar
?_?

if i save the project (the file .pas) with another name -> Ok
« Last Edit: October 03, 2019, 03:53:56 pm by metallaro1980 »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: [Tips] Circuit Simulator
« Reply #11 on: October 03, 2019, 04:07:17 pm »
Hi!

i don't understand why lazarus does not change the icon in the bar...
the icon on the other forms are right but not the icon on the bar
?_?

How do you paint on the Form1.Icon?

Please show us some code.

Winni

metallaro1980

  • New Member
  • *
  • Posts: 38
Re: [Tips] Circuit Simulator
« Reply #12 on: October 03, 2019, 04:09:01 pm »
i use the ide to set the icon on the forms.
and in the project options for the executable
maybe i must use some code?

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: [Tips] Circuit Simulator
« Reply #13 on: October 03, 2019, 06:43:06 pm »
Hm.

Is another Icon shown? Is an empty space in the taskbar?

And, important: Did you do a "save all" inbetween?

We need more information.

Winni


metallaro1980

  • New Member
  • *
  • Posts: 38
Re: [Tips] Circuit Simulator
« Reply #14 on: October 04, 2019, 12:53:23 am »
yes the icon in the bar is different to the icon in the main form
yes i done "save all" many times

 

TinyPortal © 2005-2018