Author Topic: New Plugin - CADTools  (Read 28731 times)

Offline onekk

  • CNC Jedi
  • *****
  • Posts: 525
    • View Profile
New Plugin - CADTools
« on: November 04, 2016, 17:26:41 pm »
Hi to All, After some testing and some thinking, and many many hours of programming (I've learned a lot on C# and CamBam)

Here my effort to write a CAD Tools plugin for CamBam.

It's in Beta state so there are some quirks and some testing to do:

-- The ini file CAD_Tools.ini  is created in the CamBam User directory (The parent directory of the postprocessor directory) in Windows 7 is /ProgramData/CamBam0.9.8 , at the first start the Plugin will populate it witht the default values and on exit with the last used values. (FINISHED but I need feedback

-- There is a tab Console that has no functions for now, it is intended to be a console where some command could be entered to execute some actions, (a sort of AutoCAD console). Suggestions are very welcome.

The Help test is not completely done yet something is showed.

What is Working:

C3P draw a circle using the 3 points you inserted, WORKING


POL trace a polygon selecting the center point and setting some parameters.  WORKING

You can draw a polygon supplying other than the number of sides, one of these measures:

Outer radius
Inner radius
Side Length

The plugin calculate the other quantites and display the polygon, permitting to:

1) Supply a PoinList containing : the center point, the vertex point, both of them. Or not to supply the PL
2) Draw the inner and the outer circle both of them for now.

3) Populate the TAG field of the Polyline entity with the "construction data"
4) Populate the PointList and the Circles TAG with the ID of the respective Polyline.

5) Rotate the Polyline by the "angular distance", permitting to draw i.e the "maghen David" from the triangle or to obtain a side allined with the X axis ready to rotate in place (You can draw the center point for reference).

It can rotate also  for an amount "half of the angular distance" to obtain some other effects.

The bulge field can help in avoid some tedious operation,

From what I have found the bulge:

The bulge is the tangent of 1/4 of the included angle for the arc between the selected vertex and the next vertex in the polyline's vertex list. A negative bulge value indicates that the arc goes clockwise from the selected vertex to the next vertex. A bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle.

So if you use a bulge of 1 on each side of the polygon the side is stretched to a perfect semicircle going from one vertex to another. Some artistic effects cpuld be achieved if I fixed the limmits of the bulge parameters from -10 +10 .
Let me know if it is interesting to have a more extended range.

Use:

-- Hit the POL button
-- Select the values in the interface
-- Select the center point and click.



LPP draw the perpendicular line of a Polyline.  WORKING with some quirks (sometimes it can't generate the perpendicular line)

It use the  polyline method "GetNearestPoint", the the result is quite good if the point could be "projected" on a linear segment of the polyline, near the "corners" it gave weird result, but some are 'artistic'.

-- Select a Polyline
-- fire the LPP button
-- Select a Point with the mouse and click

The perpendicular line is drawn from the point you clicked to the polyline.

SPL  Added a simple smoothing algorithm to smooth open polylines,

for closed polygon it work almost well but if you choose a smooth parameter < 0,50 some strange figures are generates, although some of them are very artistics.

Some good results are obtained when you chosse 0,750 as the smooth parameters, then apply it two or three times (apply to the new generated polyline) and then apply them "Polyline fit to Arc" function of CamBam.

-- Select a Polyline
-- Hit the SPL button
-- Insert the value for smoothing
-- Hit the Execute button

A new Polyline is created with the new values calculated.


BEZ Bezier Curve Implementation that use a Cubic Bezier Interpolation, it work quite weel as the main code is from a Open Source Project that is inspired from the Adobe Bezier implementation:

The plugin ask for the insertion of 4 points:
 1st is the starting of the curve
 2nd and 3rd are the control points
 4th is the end of the curve

After the selection is done a number of calculated interpolation points is show in the NUD, you can alter it if you put a higher number the bezier is calculated in more points (The auto calc use a rough approximation dividing by 5 the distance between the start and the end point of the pointlist if you go over five times this calculated number some strange results may appear).

-- hit Execute

If all is correct a new polyline containing a bezier curve is generated.

RND

It round the coordinates point of a Polyline to the desired number of decimals, it works even for circles rounding the center coordinates and the diameter value.

MKP Short of MarK Points

it mark some "interesting" points.

-- For Polylines it create a PointList with the midpoints of each segment, if a segment has a bulge if mark the midpoint of the arc (using CamBam.PolySegment.Midopoint value).

-- For Arcs it create a PointList with:
 1) the center of the originating circle (the same in the Arc Property Center)
 2) the midpoint of the arc (calculated by a method written by me as the half of the two angles start and sweep )
 3) both values

(On request I could add an option to divide the arc in many equals parts as the method i developed can retrieve an arbitrary point3f lying on a circle given the center and the radius)


SSP Only in v0.87 and +

This Actions take some entities and two points (defining a rectangle, I Havent' find out how to draw a rectangle like in the zoom plugin )

And Explode the Polylines in the "Rectangle" leaving what is out intact. (It can leave also the original object on demand a CheckBox)

1) Start with some entities selected
2) Hit the SSP button
3) Input the two extremas of the rectangle (example lower left and higher right or vice versa)
4) check the boxes for the verbose and leave original entities
5) Hit the Exec button

EXL Only in v0.88 and +

This Actions try to extend a polyline to a boundary formed by a polyline.

You have to:

1) press the EXL button and the Action ask:

2a) select the polyline to extend
2b) select the limiting entity
2c) select the segment of the polyline to extend (it use the polyline method GetNearestPoint so it try to guess wath you want)

Given these parameters it draw a line if there is only one intersection point
It create a PointList holding the intersection points so you can extend the polyline moving the polyline the right point to the desired position, this behaviour give you more flexibility as you can choose what target point you want to add and if you want to add or move a point.

It has some euristic, so if the segment to extend is in the middle of a polyline it emits a warning but draw the results, but no direction is guaranteed, it may use the "natural" order so the fist point is used to extend the segment.

Let me know if a chcekbox to swap the "standard" point to extend is useful or not, I didn't want to add too options if they are not "useful".

generally it guess if the segment is the first or the last point of the polyline to extend and use the "right" direction to extend the polyline.

The new line is attached at the end of the polyline as a separate entity, you have to manually join to the existing polyline.

It works even if the polyline has one segment only, but it have to guess where you want to extend the polyline so you mileage may vary, just in case a join action and selecting the old segment will extend it in the "other" direction.

If there is no intersection with the polyline it emit a warning in the Log window of Cambam.


"Settings Tab"

This Tab contains:

-- DEBUG checkbox that prints verbose information during the execution, it may be interesting to someone and when the code is correctly working and tested it could be eliminated.

-- a N of Decimals NUD input field that hold the desired number of decimals used in the NUD, (in the POL the "side length", "outer diameter" and "inner diameter"; in the SPL the "smooth" parameter)

-- A checkbox useful only by me to test the positions of the field. (it shows all the controls in the Actions Tab) (it will disappear soon)


Other info

Some other infos are printed in the CamBam Log window, many of them will be eliminated when the plugin "mature" let me know if there is some data that are useful for someone.

Verbose CheckBox

-- "Verbose Tag" that will put in the "TAG" field of the entity created some reference of the original "entity" or some other infos, ask if you want some other info or less infos.

draw Points or circles ..

"Draw Points or circles or similar" will create a PointList with some constructions points (for the BEZ the 4 points, for the C3P the 3 points, for POL the Center and the vertex or both as chosen from the ComboBox) for the SPL the options create a PointList containing the Points of the created Polyline (it may be useful if you use in a polygon a smooth param of 0.5 and you obtain the center of the sides and obiously a new polygon that joins this centers )  


Hoep it will be useful for someone

Attached the sources and a Windows dll courtesy of EddyCurrent.

I leave the v0.86 sources as the code is heavily reworked so just in case the v0.87 don't work...

New Version V0.89

The EXL Actions is improved, now it has less data to enter and it's more robust (I hope !)

Added a "Costruction" Layer where all the "costruction Points" are placed (So it'is easy to hide them when not used)


Regards


PS
I've removed some of my posts, as they are "conversational"  with other users and hold nothing interesting for other people other than some technical discussion and request for help.

I think that it's more useful for the people landing in this forum to have the relevant information not digged into many "conversational" posts, but maybe I'm wrong, let me know what do you think.
« Last Edit: November 15, 2016, 15:31:56 pm by onekk »
Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5334
  • Made in England
    • View Profile
Re: New Plugin - CADTools
« Reply #1 on: November 04, 2016, 19:34:28 pm »
Compiled dll attached but it has errors.
Filmed in Supermarionation

Offline BR52

  • Wookie
  • ****
  • Posts: 368
    • View Profile
Re: New Plugin - CADTools
« Reply #2 on: November 04, 2016, 22:33:50 pm »
Hi Eddy

You can tell how he can take out these compilation errors?

Written in portuguese of Brazil:
Você sabe dizer como ele pode tirar estes erros de compilação?

   Armando

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5334
  • Made in England
    • View Profile
Re: New Plugin - CADTools
« Reply #3 on: November 05, 2016, 09:15:41 am »
Carlo,

The error occurs if I do any of the following;

1. click the LPP button
2. click the SPL button
3. click the RND button
4. when I use BEZ and click the 4th point
Filmed in Supermarionation

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5334
  • Made in England
    • View Profile
Re: New Plugin - CADTools
« Reply #4 on: November 05, 2016, 15:42:44 pm »
Carlo,

All the buttons work okay now so removing the rich text box has fixed that.
The ini file is not populated, the output from debug is shown.

You said create an inifile, "CADTools.ini" but it should be CAD_Tools.ini
« Last Edit: November 05, 2016, 15:46:45 pm by EddyCurrent »
Filmed in Supermarionation

Offline kvom

  • CNC Jedi
  • *****
  • Posts: 1614
    • View Profile
Re: New Plugin - CADTools
« Reply #5 on: November 05, 2016, 16:33:43 pm »
There's a feature I use in Draftsight frequently that I don't think is in CB.  That is to draw a line tangent to both of two circles and whose endpoints are the tangent points.  With any two non-intersecting circles there are 4 such lines, although only the two outer ones are of interest normally.

Might be interesting to add here.

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7614
    • View Profile
    • Cambam V1.0 French Doc
Re: New Plugin - CADTools
« Reply #6 on: November 05, 2016, 22:08:50 pm »
Hello,

Quote
There's a feature I use in Draftsight frequently that I don't think is in CB.  That is to draw a line tangent to both of two circles and whose endpoints are the tangent points.

Try Draw/plus/tangent

http://www.atelier-des-fougeres.fr/Cambam/Aide/cad/Entities.htm#tangente

http://www.screencast.com/users/dh42/folders/CamBam%20Video/media/827788e6-91c9-498a-8c54-21a26d9b95f5

++
David
« Last Edit: November 05, 2016, 22:26:06 pm by dh42 »

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5334
  • Made in England
    • View Profile
Re: New Plugin - CADTools
« Reply #7 on: November 06, 2016, 09:31:31 am »
Carlo,

Yes that's where the ini file is, see picture.

Useability is okay.
Filmed in Supermarionation

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5334
  • Made in England
    • View Profile
Re: New Plugin - CADTools
« Reply #8 on: November 06, 2016, 11:54:20 am »
Carlo,

First I deleted the ini file that was already there.
When the plugin started a new ini file was created and populated, attached.

I changed some values then clicked the 'save' button, the ini file did not update.
I closed the plugin window, the ini file updated.

Filmed in Supermarionation

Offline onekk

  • CNC Jedi
  • *****
  • Posts: 525
    • View Profile
Re: New Plugin - CADTools
« Reply #9 on: November 06, 2016, 16:55:03 pm »
New Version 0.86

Added a MKP Actions it mark some points that in CamBam aren't automatically retrieved, but that have some interest when drawing.

See the first post for the mechanics,


Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5334
  • Made in England
    • View Profile
Re: New Plugin - CADTools
« Reply #10 on: November 06, 2016, 20:59:38 pm »
I've attached the Windows dll, now it's working quite good everyone can try it out.
« Last Edit: November 06, 2016, 21:19:59 pm by EddyCurrent »
Filmed in Supermarionation

Offline onekk

  • CNC Jedi
  • *****
  • Posts: 525
    • View Profile
Re: New Plugin - CADTools
« Reply #11 on: November 07, 2016, 07:26:08 am »
Thanks Eddy, I hope it is useful, I have some more ideas and I'm working on the code.

I'm trying to "modularize" most of the code, so there is a method to input and arbitrary number of points with the marking of the points (the marking method is copied from Poly Add points), and another method to input one single point.

I have modified some "drawing" method taking out the reference to the interface so they could be used elsewhere, and many little refinements.

As I'm digging into CamBam and I'm finding some interesting functions that Andy has digged, so I'm trying to use them to lenghten lines to the intersection (There is a plugin but it works incrementally) and maybe an explode routine that explode only the entities at the points into a selection rectangle, using some interesting methods present into the Polyline and the entities, but the names are promising, but the lack of documentation make hard to guess what they do, the PolyLine GetSegment() and the NumSegments are a rough example of what I'm trying to explain, NumSegments hold the number of Segments that are in a Polyline, GetSegments() I haven't found how to use it but I've found PolySegment(Poly,idx) that return the nth segments of a Polyline as a PolySegment defined as:

Code: [Select]
namespace CamBam.CAD
{
public struct PolySegment
{
//
// Fields
//
public int Index;

public Point3F P1;

public Point3F P2;

public double Bulge;

//
// Static Properties
//
public static PolySegment Undefined {
get;
}

//
// Properties
//
public bool IsLine {
get;
}

public bool IsUndefined {
get;
}

public Point3F Midpoint {
get;
}

//
// Constructors
//
public PolySegment (Polyline poly, int i);

public PolySegment (int i, Point3F p1, Point3F p2, double bulge);

public PolySegment (Line3F line);

public PolySegment (Line2F line);

public PolySegment (Arc2F arc);

//
// Methods
//
public double DistanceTo (Point2F pt);

public PolySegment[] SplitAtPoint (Point2F pt);

public object ToObject2D ();

//
// Operators
//
public static explicit operator Line2F (PolySegment seg);

public static explicit operator Line3F (PolySegment seg);

public static explicit operator Arc2F (PolySegment seg);
}
}


Thanks and Regards.


Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7614
    • View Profile
    • Cambam V1.0 French Doc
Re: New Plugin - CADTools
« Reply #12 on: November 07, 2016, 19:22:48 pm »
Hello

a VB script with getsegment()

public object GetSegment(int i); return the segment at the index position, the object can be line2F or arc2f


public Polyline GetSegment(double u, double v); return a polyline that start at U unit from the start point and with a length of V units

Code: [Select]
' New CamBam VBScript
' getsegment

sub main

'draw a polyline with arcs and lines
Dim p as Polyline = New Polyline()

p.add(6,6,0,0)
p.add(29,14,0,0)
p.add(29,35,0,0.12)
p.add(52,34,0,0)
p.add(55,18,0,0.25)
p.add(84,13,0,0)
p.add(100,28,0,0)
p.add(88,50,0,0)

doc.add(p)

'return an object = the segment at the index position

Dim o as object


Dim l as Line
Dim a as Arc

o = p.GetSegment(0) '0 contain segment 0 = line
App.Log(o.GetType.ToString) 'write object type

if o.GetType.ToString = "CamBam.Geom.Line2F" then
l = New Line(CType(o,Line2F))
doc.add(l)
end if

o = p.GetSegment(2)
App.Log(o.GetType.ToString)

if o.GetType.ToString = "CamBam.Geom.Arc2F" then
a = New Arc(CType(o,Arc2F))
doc.add(a)
end if

'return a polyline that start at U unit from the start point and with a lenght of V

dim p2 as Polyline

p2 = p.GetSegment(19,150)

doc.add(p2)

end sub



++
David

Offline onekk

  • CNC Jedi
  • *****
  • Posts: 525
    • View Profile
Re: New Plugin - CADTools
« Reply #13 on: November 08, 2016, 10:41:16 am »
Thanks David, good to know. (horrible translation from an Italian sentence).

we need some more work on the API documentation.

In Linux only C# is allowed, (There is a "new" VB compiler but I don't want to learn another language, Python, Latex, C# and a little C and Luais enough for my mind. I started programming a while ago with the C64 Basic).


Regards
Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 9098
    • View Profile
Re: New Plugin - CADTools
« Reply #14 on: November 08, 2016, 12:39:41 pm »
"In Linux only C# is allowed..."
--------------
Huh?

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"