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.