Compare commits

..

890 Commits

Author SHA1 Message Date
jean-pierre charras 2758acfd42 Fix compatibility with some old V4 schematic files.
From master branch, commit #bfe59581
2021-12-01 13:45:05 +01:00
jean-pierre charras 54c3031d74 Zone fill: When using the fillet outline option, in some cases the shape is strange.
Due to some bug in Fillet() incorrect zone outline happens in (rare) polygon shapes.
So clip it with the initial polygon (aSmoothedPoly must be contained in m_Poly)
Fixes #9692
https://gitlab.com/kicad/code/kicad/issues/9692
2021-11-19 13:55:05 +01:00
Christoph Moench-Tegeder 9a9c7856b3 Adapt OCE 3D plugin to OpenCascade 7.6.0 (for KiCad 5.1)
In line with
https://dev.opencascade.org/doc/overview/html/occt__upgrade.html#upgrade_occt760_poly
the Poly_Triangulation does not provide direct access to the internal
arrays anymore - use the accessor functions instead.
To keep changes minimal, switch only builds with a new (7.6+)
OpenCascade to the new API and keep everything else the same.

Related: !1013
2021-11-17 23:41:56 +01:00
Wayne Stambaugh 401b2fb524 Fix broken search stack behavior.
The overload of wxFilePath::FindValidPath() broke the normal behavior
when the file searched for existed in the current working directory.
This was causing the initial library table file to be copied from the
current working directory instead of from the list of search paths.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/9599

(cherry picked from commit f4b97eca63)
2021-11-13 08:43:25 -05:00
Wayne Stambaugh 0a0a2da680 Begin version 5.1.13 development. 2021-11-04 17:24:40 -04:00
Wayne Stambaugh e4df76d986 Tag release version 5.1.12. 2021-11-04 16:41:52 -04:00
jean-pierre charras 79028f1627 Handle mandatory fields name translated and not translated in SCH_COMPONENT::GetFieldText.
Fixes #9520
https://gitlab.com/kicad/code/kicad/issues/9520
2021-11-04 18:17:51 +01:00
jean-pierre charras d87e5cb809 Revert "Revert "Apply WX_LOCALE change from master branch.""
This reverts commit 3484334d15.
2021-11-04 16:47:10 +01:00
Seth Hillbrand 3484334d15 Revert "Apply WX_LOCALE change from master branch."
This reverts commit 8e9e1a618b.
2021-11-03 15:12:37 -07:00
Wayne Stambaugh 9ab6571b3f Begin version 5.1.12 development. 2021-10-27 21:33:13 -04:00
Wayne Stambaugh dad5600e7e Tag release version 5.1.11. 2021-10-27 13:53:49 -04:00
Seth Hillbrand ee56d58173 Don't raise an error for valid microvias
When the layers are adjacent, the microvia is _probably_ valid.  This is
not the case when trying to run a microvia through the core material but
without stackup information, we cannot be certain.

Note that microvias are not required in current manufacturing techniques
to be blind.

KSC Issue '400'
2021-10-27 10:52:25 -07:00
Wayne Stambaugh 9f8f2a2449 Revert "Tag release version 5.1.11."
This reverts commit f591534a0f.
2021-10-27 13:50:01 -04:00
Wayne Stambaugh f591534a0f Tag release version 5.1.11. 2021-10-26 14:51:40 -04:00
Wayne Stambaugh 7a2e0c6632 Remove old domain name from developer documentation. 2021-10-26 14:49:50 -04:00
Wayne Stambaugh 29519c5fda Revert "Tag release version 5.1.11."
This reverts commit 4c58397949.
2021-10-26 14:45:17 -04:00
Wayne Stambaugh 4b996f6bbe Revert "Begin version 5.1.12 development."
This reverts commit e4a5bfc788.
2021-10-26 14:44:41 -04:00
Wayne Stambaugh e4a5bfc788 Begin version 5.1.12 development. 2021-10-26 07:55:07 -04:00
Wayne Stambaugh 4c58397949 Tag release version 5.1.11. 2021-10-26 07:23:58 -04:00
Mark Roszko 011b4027db Add vertexIndex bounds check 2021-10-23 15:46:58 +00:00
Seth Hillbrand a1adc59cb8 Remove all references to old website
The kicad-pcb.org website is no longer valid
2021-10-18 15:47:01 -07:00
Johannes Maibaum ee4a8fc05a kicad-pcb.org->kicad.org in kicad.appdata.xml.in
kicad-pcb.org seems to cause TLS handshake errors recently.
As kicad.org is now the official domain, switch all uses of
kicad-pcb.org to kicad.org in kicad.appdata.xml.in.
2021-10-18 22:19:34 +02:00
Adam Wolf 420a3ce498 On macOS, copy libngspice dylibs and symlinks
Now that ngspice creates soversion'ed libraries, we need to tweak
how we copy the dylibs around.

This is meant to address
https://gitlab.com/kicad/code/kicad/-/issues/9143.

(cherry picked from commit ec10b12c6a)
2021-10-15 10:40:13 -07:00
Wayne Stambaugh 9b6798c479 Eeschema: yet another attempt to fix network share editing performance.
Root out a few other areas where the hierarchy integrity test was being
performed while editing where it wasn't required.
2021-10-07 07:22:50 -04:00
Wayne Stambaugh 765816ccb1 Eeschema: fix lag on network shares when duplicating and copying objects.
The delay was due to recursion checks being performed every time a new
SCH_SHEET_LIST object was created.  The fix was to back port the optional
integrity check flag added from master.  It's similar to commit 63a0f537
by Jeff Young but it could not be cherry-picked due to the changes in
master branch.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/9278
2021-10-04 16:34:30 -04:00
Seth Hillbrand f3e9e3497b Cherry-picking some external run routines
Mostly from c6bcb85562 but trees have
diverged sufficiently that there are others mixed in.  This removes the
system() call on MacOS when opening a directory
2021-09-29 11:32:25 -07:00
jean-pierre charras 8e9e1a618b Apply WX_LOCALE change from master branch.
See master branch, commits 0cf81b6 and b065ff3
2021-09-29 16:54:07 +02:00
jean-pierre charras 7272020cd3 fix use of a non const method in a const method ( from master branch) 2021-09-14 14:33:40 +02:00
jean-pierre charras 16fff71c31 Gerbview: fix incorrect bounding box of lines drawn with a rectangular aperture.
See master, commit 5abe25
2021-09-14 10:50:51 +02:00
jean-pierre charras 190223949c Gerber files: fix incorrect FileFunction attribute value for F.Fab and B.Fab layers. 2021-09-01 11:17:05 +02:00
jean-pierre charras 38d463ae49 Apply commit ddba9e2 from master: fix of not updating spice primitive field 2021-08-31 11:07:37 +02:00
jean-pierre charras 73193196d2 Cvpcb: fix possible crash when pressing the ESC key during some calculations.
From master branch, commit b1c67d9
2021-08-28 15:58:04 +02:00
Jeff Young 2975e85950 Add (a somewhat hacked) future format error for page layout files. 2021-08-27 13:16:22 +01:00
Seth Hillbrand b2fbf982a8 Don't use REALPATH to find shared/dynamic libraries
We require API compatibility in the ngspice library because we
dynamically load the library and assign function pointers to specific
names/signatures.  This should be consistent for all versions of the the
library until the soversion changes.

Fixes https://gitlab.com/kicad/code/kicad/issues/8878

(cherry picked from commit 17a17586a6)
2021-08-24 11:46:03 -07:00
Jeff Young 0843fbf904 Fix nullptr dereference.
Fixes: lp:8996
* https://bugs.launchpad.net/kicad/+bug/8996
2021-08-19 11:59:07 +01:00
jean-pierre charras 8dab9041e4 Gerbview, Excellon reader: use Leading Zeros format when not specified in file.
Some very poor files do not specify the coordinates format.
In this case, the default is INCH,LZ that looks like the more usual.
From master branch, commit b1fd462
2021-08-01 16:08:28 +02:00
jean-pierre charras 6aed98f795 Gerbview, Excellon reader: fix incorrect size of tools when the size is embedded.
From master branch, commit 70b5e26.
2021-08-01 10:26:23 +02:00
jean-pierre charras c20a76f3e2 Fix Python consoles cannot be created.
Fixes #8899
https://gitlab.com/kicad/code/kicad/issues/8899
2021-07-31 16:46:27 +02:00
Seth Hillbrand 435b1720c3 Prevent help() from blocking terminal
Ensures that the pydoc pager gets re-directed to the PyShell.  Also
keeps a copy of stdin to prevent closure in case of re-assignment

Fixes https://gitlab.com/kicad/code/kicad/issues/8047
2021-07-12 16:52:52 -07:00
Wayne Stambaugh 22bdf37fc2 Fix SPICE simulator plot bug.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/1944
2021-07-09 16:44:23 -04:00
Ian McInerney 9e3ac0eafb Don't install the import library for the 3dsg library
No one on Windows should be linking to it outside of
the build process, so there is no need for it in the
installer

Fixes https://gitlab.com/kicad/code/kicad/issues/1842


(cherry picked from commit 3bb44f3804)
2021-07-01 19:31:46 +00:00
Wayne Stambaugh 5c1c24cdab Pcbnew: fix footprint selection bug.
Do not remove footprint objects from list of selected objects when there
are no drawable objects other than the reference and value text.

Increase the minimum size rectangle for footprints from 0.025mm to 1mm
when the footprint has no drawing objects so that it is easier to select
the footprint in this case.

Add debugging code to show the footprint bounding box and polygon outline
so that it's possible to tell the difference between selection areas.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8379
2021-06-24 14:13:30 -04:00
jean-pierre charras c9cc824761 Footprint editor: fix broken mirroring of custom pad shapes.
Fixes #8649
https://gitlab.com/kicad/code/kicad/issues/8649
2021-06-23 16:31:18 +02:00
Eeli Kaikkonen b3c1e0330a OCC is the default cmake flag instead of OCE.
(cherry picked from commit 168a21bb43)
2021-06-16 12:47:58 -04:00
jean-pierre charras 4506fb2022 Fix not initialized var (m_HoleToHoleMin) in DRC when starting Pcbnew in stand-alone. 2021-06-16 11:44:02 +02:00
jean-pierre charras ecec324121 Fix a link issue created by fix 959b33c, on Linux.
Fixes #8475
2021-05-25 08:59:44 +02:00
jean-pierre charras 959b33c59b Footprint editor: fix incorrect "Zoom to Fit" when the F.Cu layer is not shown.
Fixes #8420
2021-05-14 15:30:38 +02:00
Wayne Stambaugh d6646c34ef Eeschema: fix BOM path bug in stand alone mode.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/8180
2021-05-07 15:44:21 -04:00
Wayne Stambaugh b56ac54cb2 KiCad: don't rename page description file on new project from template.
Doing so will break the link in the schematic and/or board file so copy
page description file(s) verbatim to the new project folder.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/6524
2021-05-05 07:39:22 -04:00
Mark Roszko 5bc47a0c3b Write xml netlists explicitly via wxFFileOutputStream for performance
Fix #6944
2021-05-03 23:13:38 +00:00
Wayne Stambaugh f2db83008a Begin version 5.1.11 development. 2021-04-23 13:47:08 -04:00
Wayne Stambaugh 9a01cf1b35 Tag release version 5.1.10. 2021-04-23 13:42:36 -04:00
Seth Hillbrand 0f6f30b26e Ensure collapsed tree before update
We had been maintaining the tree collapse state for "clear" actions
where the user went back to no object search.  This was helpful in the
case where we had previous items (e.g. last placed element)

But this causes isses when a sub element was previously select on GTK.
Now we choose safety for GTK over the pretty display

Fixes https://gitlab.com/kicad/code/kicad/issues/8198
2021-04-20 11:50:08 -07:00
Marek Roszko 8219334806 Fix wrong offset in msys2 x64 libcontext implementation not saving fiber data pointer
This should have/may have been causing random crashes on calls into win32 api.
fiber data is located at offset 0x20 of the stack not 0x18.
2021-04-12 19:11:44 -04:00
Wayne Stambaugh e6997d87b3 Eeschema: fix zero length line segfault.
Clear the current draw item when line segment clean up results in no lines.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8175
2021-04-12 14:41:52 -04:00
jean-pierre charras 13b453c21e PDT plotter: fix incorrect header (from Master branch) 2021-04-06 11:34:52 +02:00
Seth Hillbrand 4ec3f18fda Return wxString for gfx importer messages
Returning a reference to a temporary value crashes when the value is
deallocated before use.  Passing a full string fixes the crash and
allows NVRO on the temporary value.
2021-04-04 06:20:14 -07:00
Jon Evans fc8ffd8421 Disable Cairo canvas for Mac
Fixes https://gitlab.com/kicad/code/kicad/-/issues/7052
2021-04-02 18:50:21 -04:00
Seth Hillbrand 4551651777 Fix empty translated string 2021-04-02 11:12:39 -07:00
Marek Roszko 82f2e8c344 More gracefully handle tinyspline not liking a spline definition
Partial fix for #6634

(cherry picked from commit e409b04538)
2021-04-02 09:41:22 -07:00
jean-pierre charras b76c5c9433 Drill map report: use more digits in float values for diameters. 2021-03-29 11:21:24 +02:00
Jon Evans 1737927814 Fix cherry-pick error 2021-02-17 08:12:05 -05:00
Graham Keeth 38d7ac6d9c Add BOM file extension to BOM plugin command line
Attempt to parse BOM output file extension from BOM plugin header, and
append it to the "%O" argument in the BOM plugin command line.

Fixes #6943

(cherry picked from commit f54ab830f6)
2021-02-11 21:19:31 -05:00
Seth Hillbrand db1bf4351b Fix GTK crash when multiple libraries are expanded
Once more into the gtk_tree_view breach.

This may also be related to https://gitlab.com/kicad/code/kicad/-/issues/7344

Fixes https://gitlab.com/kicad/code/kicad/issues/7422

(cherry picked from commit 4657ca5d4f)
2021-02-08 14:36:08 -08:00
Seth Hillbrand 2d491f9cbd Update multi-unit symbols uniquely
This updates multi unit symbols uniquely even when the schematic is
unannotated (and therefore there are multiple symbols with the same
reference).  We attempt to enfore a single unit update per symbol and
test for both value and reference commonality before assuming that the
unit is part of the larger multi-unit symbol

Fixes https://gitlab.com/kicad/code/kicad/issues/7117
2021-01-14 14:52:55 -08:00
Johannes Maibaum a58d0f8a67 Add diode model to rectifier demo (ngspice-32 fix)
Patch by Holger Vogt

Fixes https://gitlab.com/kicad/code/kicad/issues/4453
2021-01-14 20:24:36 +01:00
Johannes Maibaum 42cd6ca4ca Fix screenshot sizes in kicad.appdata.xml.in 2021-01-13 18:14:33 +01:00
jean-pierre charras f292f1628b Spice sim: fix incorrect (very large) dialog size displaying the netlist.
It was previously fixed to 1500x900 pixels, that can be too large.
The window size and position is also now retained during a session.
From master branch, commit 60152bc
2021-01-11 10:55:51 +01:00
Seth Hillbrand 20909d4948 Fix crash when deleting symbol in GTK
So many things can go wrong with this control in GTK.  We have to
collapse the tree when updating the search string to avoid a crash when
referencing a child object but collapsing the tree will iterate over
elements and crash when we have deleted a symbol.

The temporary fix for this nonsense is to carefully order the calls.
We only need to collapse the search tree if we are not keeping our state
(in other words if we are fully re-building the tree)

Fixes https://gitlab.com/kicad/code/kicad/issues/6910

(cherry picked from commit 8af4cf88a0)
2021-01-04 09:38:51 -08:00
Jeff Young 1f6ff4a519 Fix access into empty container.
Fixes https://gitlab.com/kicad/code/kicad/issues/6840

(cherry picked from commit 359c29639f)
2021-01-04 09:26:01 -08:00
jean-pierre charras 07568f87c3 Step exporter: better values for min distance between 2 points to merge them.
- The default value is 0.01 mm (according to comments and similar to the 3D viewer
 settings that uses 0.02 mm)
- The export dialog  has now 3 values 1 micron, 0.01mm (default) and 0.1 mm

From Master branch, commits a9feb1c and 5db7580
2021-01-03 14:52:42 +01:00
Mikołaj Wielgus 267e510071 Update PCBMODEL::SetMinDistance to set BRepBuilderAPI precision
Fixes #3818
2021-01-03 13:39:38 +01:00
Marek Roszko 73b921d591 Correct assembly opcode 2021-01-02 16:20:50 -05:00
Marek Roszko 8677035989 libcontext: Call exit instead of random memory address on MSW x86_64
cherrypick of 580293c7fa

See #6820
2021-01-02 16:18:10 -05:00
jean-pierre charras a179893d70 specctra_export: fix an issue with custom pads.
From Master, commit 686254.
In some cases a created pad stack name had the same name as an other pad stack
having a slightly different shape, thus creating pads with a incorrect shape on board.

Fixes #6495 for the 5.1.10 branch.
2020-12-29 17:41:36 +01:00
Jan Mrázek 540fb91d34 Backport 93466fa1: Fix crash when adding 3D Models via Python 2020-12-28 23:22:16 +01:00
Wayne Stambaugh 591a07d2d9 Begin version 5.1.10 development. 2020-12-22 15:09:32 -05:00
Wayne Stambaugh f607e913d5 Tag release version 5.1.9. 2020-12-22 15:05:01 -05:00
jean-pierre charras 3d57de91e8 SCH_SHEET::SearchHierarchy(): fix an issue when comparing file names.
We are using the unix separator in filenames in all platforms.
However on Windows some filenames can contain native separators.
We now ensure all filenames use the unix separator before comparison.

Fix #6742
2020-12-20 14:32:25 +01:00
Marek Roszko 9fbceaa458 Nix another easily triggered infinite event loop on Windows
This infinite loop was triggered on any dynamic scaling change with KiCad open.
Either local display scale change OR Remote Desktop.
2020-12-19 17:07:22 -05:00
Jon Evans 281180512f Prevent refresh loops on GTK/MSW
Fixes https://gitlab.com/kicad/code/kicad/-/issues/6787
2020-12-19 14:48:13 -05:00
qu1ck 50fa1937f9 Read fp-info-cache on first start of fp editor
if fp info list is not initialized
2020-12-19 00:48:42 -05:00
Jon Evans d79aee3f78 Fix refresh logic on MacOS to prevent excessive redraws
This new logic does not need to be MacOS-specific; it should
account for timer inconsistencies on any platform.

Thanks to Mark for the suggestions.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/6222
Fixes https://gitlab.com/kicad/code/kicad/-/issues/6332
2020-12-18 13:52:57 -05:00
jean-pierre charras f599185e2d fp editor: fix incorrect parent for a error message box
From master branch (commit b425889)
2020-12-17 11:25:12 +01:00
Wayne Stambaugh fd79c7ae46 Eeschema: fix assertion creating a new sheet.
Fixes https://gitlab.com/kicad/code/kicad/issues/6722
2020-12-16 16:21:15 -05:00
Marek Roszko 9de0846f3e Formatting
Because I can't use a real IDE with msys
2020-12-14 20:06:44 -05:00
Marek Roszko f168ece461 Disable the wxFileSystemWatcher on network shares
Fix #5740
Fix #4126

This is a stupid solution because SAMBA sends invalid events and wxWidgets decides to assert rather than ignore them.
Why can't people just use Windows Server shares :(
2020-12-14 20:02:18 -05:00
Ian McInerney 4100650ce1 Fix some new compiler warnings on GCC 10 2020-12-15 00:24:42 +00:00
Marek Roszko 87bb437fd3 Fix formatting 2020-12-14 08:28:57 -05:00
Marek Roszko 626c671448 Reset frame position when wxDisplay cannot find the matching display
Fix #6732
2020-12-14 08:28:04 -05:00
Wayne Stambaugh b532c4a2b8 Eeschema: fix overzealous save file update UI event handler.
Apparently wxFileName stats the file on Windows when using the == operator
which causes slow response when adding sheets in designs saved on remote
shares.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/5596
2020-12-13 21:08:49 +00:00
jean-pierre charras 276cb7590d Gerber: speed up seriously solder mask creation.
Fixes https://gitlab.com/kicad/code/kicad/issues/6360
2020-12-13 18:53:17 +01:00
Marek Roszko f66aae2213 Fix flickering on msgpanel paints 2020-12-11 23:21:26 -05:00
Marek Roszko 17c4e21f34 Use a temp file for saving the fp-info-cache for now 2020-12-11 22:36:54 -05:00
Marek Roszko 3613bca5ea Read the fp-info-cache on pcb file load rather than on frame open
Otherwise in standalone mode pcbnew will never load the cache files and also later erase them :/
2020-12-11 22:36:47 -05:00
Marek Roszko eff9c46e59 Replace wxTextFile for writing fp info cache
wxTextFile uses wxFile which uses write syscalls which means its unbuffered.
This makes file IO more expensive against network shares where it will flush far too aggressively.
wxTextFile is fine for reads however.
2020-12-11 22:34:56 -05:00
jean-pierre charras c186a42a54 Replace wxFloatingPointValidator by our UNIT_BINDER in DIALOG_PAD_PROPERTIES.
the change is a try to fix an annoying issue (#6499 similar to #6670) we cannot
reproduce but is probably related to a locale issue.
2020-12-09 19:50:28 +01:00
jean-pierre charras 676d35f559 Replace wxFloatingPointValidator by our UNIT_BINDER in DIALOG_TEXT_PROPERTIES.
wxFloatingPointValidator has some limitations, but mainly the change is a try
to fix an annoying issue (#6670) we cannot reproduce but is probably related
to a locale issue.
2020-12-09 19:45:03 +01:00
Wayne Stambaugh e8bc4632b4 Minor dialog and other layout fixes.
* Fix clipped bitmap buttons.
* Remove colons from the end of wxStaticBoxSizer strings.
* Minor padding improvements.
2020-12-08 09:19:32 -05:00
Jeff Young 222158e954 Don't free part before removing from view. 2020-12-07 17:04:29 +00:00
Mark Roszko dde87b2f45 Prevent dxf imports of text from processing NaN coordinates 2020-12-05 01:55:39 +00:00
jean-pierre charras 789284f519 Pcbnew, modifiers for left click behavior.
Due to last changes fixing the ALT key problems, the highlight net is
CTRL+SHIFT + left click on Windows and Linux
CTRL+ALT + left click on OSX
Fix also a bad behavior of "remove from selection" left click option

Fixes #6599
https://gitlab.com/kicad/code/kicad/issues/6599
2020-12-04 12:05:46 +01:00
jean-pierre charras 19576ae167 Fix a compil issue 2020-12-04 10:44:23 +01:00
Mark Roszko be8fe7bdd6 Block off potential errant double activation of tree project items
Additional fix for #6606

Cherrypick from 535dbc1a06
2020-12-04 02:15:07 +00:00
Seth Hillbrand d7a6a2cc71 Fix locking scheme for double-clicks
In some cases, the events may be driven in the same thread, which can
lead to a deadlock.  Instead of waiting for the lock, simply refuse to
run if a loading system in in progress.

Fixes https://gitlab.com/kicad/code/kicad/issues/6606
2020-12-03 14:30:17 -08:00
Seth Hillbrand 7eea344f91 Fix/workaround GTK libtree issue with multi-unit symbols
When preparing for clearing the tree, GTK requires walking through
parents.  After calling "Freeze()" to protect against returning bad data
(see #6458 and #4471), we can no longer access Parent() from GTK and the
tree cannot be cleared.

The fix is to collapse the first element if it is open.  This prevents
the common case of the history elements being expanded in the tree

Fixes https://gitlab.com/kicad/code/kicad/issues/6102
2020-12-03 14:12:58 -08:00
Ian McInerney 2bd0b67591 Link kicad appdata with the desktop file
This link is needed to ensure appstream-builder finds
the icon for the program and includes it in the appstream
metadata for distribution software centers.

Fixes https://gitlab.com/kicad/code/kicad/issues/6593

(Cherry-picked from 9c968b0ef7)
2020-12-02 19:41:20 +00:00
Steven A. Falco d9307a174d Update desktop files, substituting Science for Development.
KiCad more properly fits into the Science and Engineering category.

(Cherry-picked from 675bb90128)
2020-12-02 19:40:58 +00:00
Seth Hillbrand 59c5b30f3f CMake adjust Linux build
Instead of linking the same target name and re-building, we can install
the file to a new name.  This speeds the build process and keeps linking
routines from stepping on each other.  Available now that we are at
CMake 3.0.2

Fixes: lp:1789468
* https://bugs.launchpad.net/kicad/+bug/1789468

(cherry picked from commit 51511eda85)

Fixes https://gitlab.com/kicad/code/kicad/issues/6576
2020-12-02 08:28:49 -08:00
Seth Hillbrand 938859f10a SPICE export full precision data
Saving csv files loses precision when time/data steps are smaller than
10^-6.  This switches to engineering notation when dealing with higher
precision.

Ref KiCad Services ticket 281
2020-11-30 13:26:10 -08:00
jean-pierre charras a9b53d94e8 Page layout editor: fix missing scrollbars in properties panel (GTK specific) From master branch 2020-11-30 20:24:47 +01:00
jean-pierre charras a33e2ed9b1 gendrill_file_writer_base: better algo to sort holes:
Holes were correctly sorted by size, but inside the same hole size
the holes were strangely sorted.
Now holes are sorted by hole size, and (inside the same size) by position.

From master branch
2020-11-30 20:22:30 +01:00
Wayne Stambaugh 7687ca2080 Pcbnew: change block selection and heuristic context menu modifier keys.
Do not use the alt modifier key to force the display of the heuristic
context menu.  This causes a conflict with menu selection on windows
and immediately dismisses the disambiguation context menu.

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/1873
2020-11-30 11:47:15 -05:00
jean-pierre charras 2a1a6e8cbe From master branch: Make path substitutions grid read only in lib table dialog
From master branch, commit becc811.
2020-11-29 13:21:15 +01:00
jean-pierre charras 45fa9e8448 bitmap2component.cpp: ensure polygon calculation use PM_STRICTLY_SIMPLE option. 2020-11-29 13:18:01 +01:00
Steven Falco 0ca66d1af3 Add python 3.10 detection to CMake
(Cherry-picked from d85d0efdd8)
2020-11-28 22:28:10 +00:00
jean-pierre charras 63baa69342 Some fixes from master branch:
- fix environment variable changes after running Pcbnew in some cases.
- kicad manager: correct bitmap icon for gerber job files
- incorrect position of some checkboxes (not readable) when compiled with
wxWidgets 3.1.4
2020-11-21 15:56:54 +01:00
taotieren 894291faba Update Linux appdata file 2020-11-10 13:38:39 +00:00
jean-pierre charras 51708bab49 Gerbview, Legacy graphic mode: fix missing or incorrect inits related to zoom.
Fixes #6326
https://gitlab.com/kicad/code/kicad/issues/6326
2020-11-09 10:32:12 +01:00
jean-pierre charras 4497a754fb clear flags after a block placement (that previously leave moved item shown
in the selected state color)
2020-11-08 10:57:13 +01:00
taotieren 6223e7475c Add Simplified Chinese desktop file translations 2020-11-06 11:50:15 +08:00
Seth Hillbrand bf97378168 Don't allow selection of PCB_NETINFO_T
This is a version of master commit d9a94dc538
but that cannot be cherry-picked because it contains a number of
unrelated modifications

Fixes https://gitlab.com/kicad/code/kicad/issues/5729
2020-11-03 10:19:04 -08:00
Mark Roszko 5a6f291c72 Remove infinitely recursive loop on Windows (in special cases)
This looks like it was always intended for macOS but was accidentally changed for Windows as well.
If this is a requirement on windows, I'm sure theres better ways to fix it....

Cherrypick from 98ece9d
2020-11-02 13:45:14 +00:00
Roberto Fernandez Bautista 3404f4e86b Check GLEW functions exist before calling them
Fixes https://gitlab.com/kicad/code/kicad/-/issues/6235
2020-10-30 19:45:33 +00:00
Roberto Fernandez Bautista 6c07ebe5f2 Combine return statements in OPENGL_GAL::CheckFeatures 2020-10-30 19:43:22 +00:00
Roberto Fernandez Bautista 24a4f06013 Fix OPENGL_GAL initialization sequence (Version for 5.1)
- New public static function OPENGL_GAL::CheckFeatures() gets called in EDA_DRAW_PANEL_GAL::SwitchBackend() before switching to OPENGL_GAL
- Moved all OpenGL feature checks from OPENGL_GAL constructor to OPENGL_GAL::init()

Fixes https://gitlab.com/kicad/code/kicad/-/issues/4714
2020-10-30 17:38:19 +00:00
Seth Hillbrand 73bf4cbce7 Unselect and freeze before starting reset
In some cases, the BeforeReset() will cause an iteration over the tree
elements.  If we have deleted an element before doing this, we risk a
corruption/crash.

Fixes https://gitlab.com/kicad/code/kicad/issues/6192

(cherry picked from commit 3bd080b64e)
2020-10-30 10:00:36 -07:00
Wayne Stambaugh 67c8071bf4 Begin version 5.1.9 development. 2020-10-30 08:37:55 -04:00
Wayne Stambaugh 9b163cb444 Tag release version 5.1.8. 2020-10-28 15:28:02 -04:00
Wayne Stambaugh 83d6a77617 Eeschema: fix symbol rescue bug.
Loading the schematic symbol preserves the invalid LIB_ID characters in
the symbol name.  Unfortunately, loading the library symbol automatically
fixes the invalid characters so this caused the symbol rescue to not find
library symbols with invalid characters.  Replacing the invalid characters
in the schematic symbol name during rescue fixed the issue.  This fix
isn't perfect because there is the off chance that replacing the invalid
characters could lead to a name clash in the library resulting in the
incorrect symbol to be rescued.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/2319

(cherry picked from commit d90d734166)
2020-10-28 09:45:27 -04:00
Marek Roszko e5e174a20e Avoid 3d viewer stealing back focus/activation
Fix #6184
2020-10-27 19:41:14 -04:00
Seth Hillbrand 8aede85214 Correct freeze ordering in lib_tree_model
Adapts the BeforeReset()/AfterReset() logic to the 5.1 branch

Fixes https://gitlab.com/kicad/code/kicad/issues/6102
2020-10-26 11:28:58 -07:00
Seth Hillbrand c625b9e3cc Remove errant printf
(cherry picked from commit cce11e40a1)
2020-10-23 14:47:39 -07:00
Seth Hillbrand 222d44a8d8 Fully freeze tree GUI
This is the v5 analog of 0d6684bdf

Fixes https://gitlab.com/kicad/code/kicad/issues/6102
2020-10-23 12:35:14 -07:00
Seth Hillbrand 386f827d38 Be diligent in our search for color information
Just because we find a label reference does not mean that is where the
color is stored.  We do an exhaustive search through the hierarchy for
the correct color data

Fixes https://gitlab.com/kicad/code/kicad/issues/6107

(cherry picked from commit 75c2d1a0bf)
2020-10-23 12:13:34 -07:00
Marek Roszko 831c51c875 Launch tools from Idle in the kicad manager.
Launching on a control event can allow that control to steal focus from the new windows as more events may exist intended for the control.

Fix #4479
2020-10-17 00:58:17 -04:00
Marek Roszko 2d25d37112 Fix focus theft, Windows sends mouse events to windows regardless of focus.
We need to check if the window is foreground before fight over focus which will make the window foreground if it wasn't.

Fixes #4099
Fixes #5958
2020-10-17 00:53:26 -04:00
Mark Roszko a3172d643f Add wxTimer stallout fix to tool dispatcher 2020-10-15 04:51:07 +00:00
Seth Hillbrand 02787784a4 Bump OCE Plugin version
We modified how we search for color information.  Changing the version
data will for models to reload instead of keeping the cached data with
(possibly) missing color information

(cherry picked from commit b51ca1ab0e)
2020-10-14 08:49:46 -07:00
Seth Hillbrand 967f390aec Seach full model for color information
Assemblies may not have their face information in the top level of the
file.  Search recurses to get the explicit shape in sub assemblies as
well.

Fixes https://gitlab.com/kicad/code/kicad/issues/5163

(cherry picked from commit a2168c6add)
2020-10-14 08:49:18 -07:00
jean-pierre charras 89951b01ff Fix incorrect vertical position of check boxes in some wxGrid on wxWidgets 3.1.4.
Fix also 2 compil warnings.

These fixes come from the master branch
2020-10-04 09:55:09 +02:00
Wayne Stambaugh ca8f026bc3 Begin version 5.1.8 development. 2020-09-25 16:06:11 -04:00
Wayne Stambaugh 4c14d7ef5a Tag release version 5.1.7. 2020-09-25 15:49:58 -04:00
Seth Hillbrand 8234c20e28 Remove threading from Python wrapper
Python threading can cause issues with zone filler, connectivity
calculations and many other parts.  This forces the emitted code to hold
the GIL when running.

Fixes https://gitlab.com/kicad/code/kicad/issues/4436
2020-09-15 17:11:12 -07:00
jean-pierre charras 52e272954f Fix a DRC crash if a zone is flagged as filled but has 0 filled areas
Fixes #5631
https://gitlab.com/kicad/code/kicad/issues/5631
2020-09-15 14:18:23 +02:00
Seth Hillbrand 77caf50265 Remove OGLTest
We don't use this utility nor do we have plans to

(cherry picked from commit de12d40ee6)
2020-09-12 06:49:51 -07:00
jean-pierre charras 2ab8751fd4 Drill files export: ensure the Top to Bottom PTH drill file is always created,
even if there are no hole. NPTH file is already always created.

From Master.

Fixes #5566
https://gitlab.com/kicad/code/kicad/issues/5566
2020-09-10 17:04:01 +02:00
jean-pierre charras 54589c0828 FOOTPRINT_WIZARD_FRAME::ParametersUpdated(): fix a reentering issue
On wxWidgets 3.0.5, in some cases calling ReCreateParameterList() generates
a EVT_GRID_CMD_CELL_CHANGED that call ParametersUpdated()
and creating an infinite loop
Note also it happens **only for languages using a comma** instead
of a point for floating point separator
It does not happen on wxWidgets 3.1.4

From master branch
2020-09-08 19:02:17 +02:00
Seth Hillbrand 1fdb247167 Reverts premature Python 3 calls in favor of backwards compat.
This reverts commits d8d8f4f670
and 9614f6d0d9.

(cherry picked from commit 91914f1a71)
2020-09-03 20:06:28 -07:00
Wayne Stambaugh 49cc47afd1 Eeschema: fix broken new sheet path comparison on windows.
Using wxFileName::GetPath( wxPATH_WITH_SEPARATOR ) does not include the
drive specifier (A:, B:, C:, etc.) on windows which fails the comparison
with the project path 100% of the time.  wxFileName::GetPathWithSep()
solves the issue nicely.

Fixes https://gitlab.com/kicad/code/kicad/issues/5077

(cherry picked from commit 03423f13a1)
2020-09-03 14:26:31 -04:00
Wayne Stambaugh 673677c831 Eeschema: fix segfault when auto save file is detected.
Fixes https://gitlab.com/kicad/code/kicad/issues/5068
2020-09-01 10:29:06 -04:00
Ian McInerney c30dc04571 Skip the slider event to allow the stepping to work
The stepping is in a static event handler, so it is called
after the dynamic handler and so the dynamic handler must
allow the event to continue processing.

Fixes https://gitlab.com/kicad/code/kicad/issues/5319
2020-08-29 23:32:11 +01:00
Ian McInerney f58de79ceb Provide a checkbox to use negative coordinates in the position file
ADDED: A checkbox to allow selection of positive/negative X coordinates
for bottom components.

Fixes https://gitlab.com/kicad/code/kicad/issues/4638
2020-08-29 23:17:29 +01:00
Seth Hillbrand 8d9bb7a63e libedit: Unselect before re-syncing
The library alias may change so we need to ensure that the underlying
selected lib_id is not maintained across regenerations.

Fixes https://gitlab.com/kicad/code/kicad/issues/5144
2020-08-26 10:10:43 -07:00
Marek Roszko 18490162f7 Use a local tmp file for plotting
Fix #5238

(cherry picked from commit de7a1b647c)
2020-08-20 15:28:18 -07:00
jean-pierre charras bf71a4e012 Gerbview: fix draw issue when drawing a line using a rectangular aperture.
Lines using a rectangular aperture are not common, but this is legal in Gerber files.

Fixes #5205
https://gitlab.com/kicad/code/kicad/issues/5205
2020-08-18 10:26:10 +02:00
Seth Hillbrand d29edf6381 Removing extra parameters to super() calls
The extra parameters seem to cause problems for some Python
configurations and are not needed.

Fixes https://gitlab.com/kicad/code/kicad/issues/4896

(cherry picked from commit d8d8f4f670)
2020-08-12 06:33:22 -07:00
Blake Smith b087b7743e Fix PadGridArray super call
(cherry picked from commit 9614f6d0d9)
2020-08-12 06:33:21 -07:00
Ian McInerney 8ee1a7f67f Preserve the externally defined variables in the configure paths dialog
Previously the variables that were defined externally weren't being
readded to the variable map, so they would not appear in the dialog
the next time.

(Cherry-picked from fedc6519cd)
2020-08-12 00:29:17 +01:00
Ian McInerney 475385d876 Force regeneration of the lib tree on first load
Just setting the text field is not guaranteed to fire
a text event, so we must forcefully call the regenerate
function to ensure the preselect is handled.

Fixes https://gitlab.com/kicad/code/kicad/issues/4105

(Cherry-picked from 63b53c3968)
2020-08-12 00:27:33 +01:00
Ian McInerney 1b967a07e5 Remove shadowing linewidth member from the Cairo GAL
The base GAL has the linewidth property already, and its
accessor will only return the base version. This was causing
problems with the Cairo printing GAL, since that setter wasn't
using the base class version. Also, this removes the print-specific
setter, since the actual setting of line width shouldn't be done
there and is instead done where the drawing happens.

Fixes https://gitlab.com/kicad/code/kicad/issues/5089

(Cherry-picked from 5684708b22)
2020-08-11 00:54:23 +01:00
Ian McInerney 1088d613d5 Escape all env var strings sent to the Python interpreter
Fixes https://gitlab.com/kicad/code/kicad/issues/5130

(Cherry-picked from 0a0ed9e064)
2020-08-11 00:53:48 +01:00
Ian McInerney 1b2d4d6522 Entries typed into the text size field should be read as mils
Previously, they were being interpreted as inches, and then being
displayed as mils - leading to a multiplication by 1000 if there
was no unit string included.

Fixes https://gitlab.com/kicad/code/kicad/issues/5117

(Cherry-picked from 259cacf648)
2020-08-11 00:52:05 +01:00
Seth Hillbrand 0fd1214dea pcbnew: Fix multiple issues with BOARD_CONNECTED_ITEM
Modules are not members of BOARD_CONNECTED_ITEM, so we cannot use this
as a proxy for membership in the connectivity or ratsnest calculations.

Fixes https://gitlab.com/kicad/code/kicad/issues/5140
2020-08-10 12:53:37 -07:00
Jeff Young 00547b7aac Fix compile errors on CLang. 2020-08-10 20:06:06 +01:00
Jeff Young 621bfe36a8 Convert smart quotes and dashes in reports to ASCII quotes and dashes.
Fixes https://gitlab.com/kicad/code/kicad/issues/1861
2020-08-10 18:30:46 +01:00
Jeff Young c1849f7e00 Don't throw out search hits because they have unit children.
(Cherry-picked from 6aa0ceff36)

Fixes https://gitlab.com/kicad/code/kicad/issues/3746
2020-08-10 17:04:36 +01:00
Ian McInerney b23db7c4cb Fixup the UI for the symbol preview widget
This is the proper fix for the symbole preview widget. It will ensure
there are no size changes between the two panels (preview and status),
and also ensure that the status panel has the same background color as
the preview panel.

Fixes https://gitlab.com/kicad/code/kicad/issues/4997
2020-08-10 00:52:48 +01:00
Ian McInerney b3525bc642 Hide the scrollbars on the symbol preview canvas
This canvas supports mouse interaction, and navigating using the
scrollbars is very difficult (it causes large jumps). Also, having
the scrollbars causes the background to bleed through around them,
making them appear floating in the canvas.

Fixes https://gitlab.com/kicad/code/kicad/issues/4997
2020-08-09 23:13:03 +01:00
Ian McInerney 589951eaea Ensure the environment variables are synced between Pcbnew and Python
This ensures that when the project or an environment variable is changed
in pcbnew, the Python interpreter is updated to reflect that.
This is a backport version of the master-branch commit, and will not
synchronize any changes to the environment variables if they are made
from frames other tna Pcbnew.

Fixes https://gitlab.com/kicad/code/kicad/issues/5071
2020-08-09 20:32:38 +01:00
jean-pierre charras 74adbbcc5d Ensure values with units are displayed correctly when numbers are very small.
from master branch.
see https://gitlab.com/kicad/code/kicad/issues/5074
2020-08-09 09:48:10 +02:00
Ian McInerney bab61dd249 Initialize clear annotation variable to false so they aren't cleared by accident
When it was uninitialized, cancelling the dialog could lead to the
sheet's annotations being cleared because the variable wasn't set
to false anywhere.
2020-08-08 23:24:36 +01:00
Ian McInerney 5c3bcb09fa Give the length tuning tool an inital end point that isn't the start point
Using the starting point as the end point means that the tool
initializes with 0 length traces and so nothing is visible.

Fixes https://gitlab.com/kicad/code/kicad/issues/1912
2020-08-08 22:55:18 +01:00
Ian McInerney f0b94dd0d4 Load the previous project if an empty string is the argument
Previously it would just not open any project at all. This
was a problem for some launchers, which would pass an empty string
when no file is passed by the user.

Fixes https://gitlab.com/kicad/code/kicad/issues/5055
2020-08-08 22:55:03 +01:00
jean-pierre charras ba5ab99a03 pcbnew: More about Prevent use of non-connected item in ratsnest
Another static cast was left. changed now to dyn_cast

We need to be careful in the connectivity system to always use
dyn_cast/dynamic_cast and check the return when dealing with board
items.
Fixes https://gitlab.com/kicad/code/kicad/issues/5082
2020-08-08 09:59:54 +02:00
Seth Hillbrand 9bc3028eb7 pcbnew: Prevent use of non-connected item in ratsnest
We need to be careful in the connectivity system to always use
dyn_cast/dynamic_cast and check the return when dealing with board
items.  Getting non-connected items will result in null nets when
propagated.

Fixes https://gitlab.com/kicad/code/kicad/issues/5082

(cherry picked from commit 406de56964)
2020-08-07 14:09:03 -07:00
Wayne Stambaugh 5ef9db6d67 Eeschema: fix large diffs when saving schematics.
Apparently the < operator was never implemented for SCH_JUNCTION objects
so they were not get sorted which was causing the large diffs between
schematic saves.

Fixes https://gitlab.com/kicad/code/kicad/issues/4370

(cherry picked from commit 35f3eb6220)
2020-08-06 09:27:14 -04:00
jean-pierre charras 86a710e175 Gerbview: show a message instead of an error when trying to open a job file as plot file.
From master branch, commit ef0ae8
2020-08-06 14:59:29 +02:00
Tormod Volden 1797a9c61a bom2grouped_csv.xsl: Fix sorting of grouped references
Commit a96ebe8f seems to have missed a dollar sign.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/940
hopefully for good this time.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>

(Cherry-picked from e82e30d215)
2020-08-06 10:14:26 +01:00
Frank Severinsen fd49bc5d8d Check reference designator type when comparing comp
example: prevents a 10K NTC resistor from getting grouped with a 10K SMD resistor

(Cherry-picked from 9ca61b50b6)
2020-08-06 10:12:57 +01:00
Matthias Urlichs de4c6c6fab Allow SWIG 4.0.
No other changes are necessary.

(Cherry-picked from 3bba96baa2)
2020-08-06 10:06:24 +01:00
Ian McInerney 78a7dd3269 Properly dismiss the grid combobox editor when it loses focus
The old way of checking for focus loss caused GTK to be unable to
even open the combobox. This way checks for the event sent when the
list closes and uses that to close the grid editor.

Fixes https://gitlab.com/kicad/code/kicad/issues/4617

(Cherry-picked from af24a5d5a7)
2020-08-06 02:02:32 +01:00
Wayne Stambaugh 0cf53da0fe Fix ngspice version information issue.
The config.h header for ngspice is not packaged with all platforms so
use pkg-config to fetch the version information when available.  When
pkg-config is not available, check if the ngspice/config.h file is
installed on the system before including it to build the ngspice version
string.  If neither pkg-config or ngspice/config.h is available set the
version string to "unknown".

Fixes https://gitlab.com/kicad/code/kicad/issues/4851
2020-08-02 15:49:25 +02:00
jean-pierre charras 13b8708e58 Better fix for OPENGL_GAL::DrawSegment() than initial commit 5bdc78e.
segments having a length <= 1 internal unit are not drawn in opengl gal.
So these segments are drawn as circle.
Fix from master branch.
2020-07-31 15:44:24 +02:00
Simon Richter b6d91bd28a Remove commented-out code for building cvpcb.exe 2020-07-31 14:12:32 +02:00
Seth Hillbrand 5bdc78e3ba GAL: Fix issue with small tracks being hidden
When drawing segments that are smaller than the segment width, OpenGL
did not use realistic values, leading to hidden, small tracks.  Instead,
we set the track to only draw a segment when the length is at least 1
radius long (so that we can see the full semi-circle at the track end)

Fixes https://gitlab.com/kicad/code/kicad/issues/5009

(cherry picked from commit 294dabf640)
2020-07-30 15:12:17 -07:00
Seth Hillbrand bce8fb31ab Mirror hidden text in SVG plotter
We output a 0 opacity text in the SVG plotter to allow searching.  When
this text is changed to 100 opacity, it can show up on the user screen
and so needs to be mirrored to match the stroke font output

Fixes https://gitlab.com/kicad/code/kicad/issues/5001

(cherry picked from commit b650e4568b)
2020-07-30 06:26:49 -07:00
jean-pierre charras 77d7d21130 Simulator: optimize a plot function, to support large amount of points.
Redundant points are not plotted.

From master, commit 010316457
2020-07-29 08:55:45 +02:00
Seth Hillbrand fed1520a8e Treat 0-length ovals as circles
Some buggy SVG interpreters can't handle 0-length ovals.  In this case,
they are meant to be circles, so we can export as circles in our
plotter.

Fixes https://gitlab.com/kicad/code/kicad/issues/3995

(cherry picked from commit e38ab6c699)
2020-07-28 09:53:26 -07:00
jean-pierre charras 284d5861dd Remove creation on the fly of wxPaintEvent instances, not allowed in 3.1.4 wxWidgets
From master branch
2020-07-18 08:24:58 +02:00
Urja Rannikko ee6154c842 GAL: Remove dead code regarding SHADER_LINE_B in the fragment shader
The only test for it was only called from a function
that's called if the mode is SHADER_LINE_A, not B.

(cherry picked from commit 65ceeebc71)
2020-07-17 14:10:29 -07:00
Urja Rannikko 709197c294 GAL: Round the incoming mode parameter in fragment shader
This fixes some letters being randomly boxes and some circles
being randomly triangles on the Mali T760.

(cherry picked from commit aa7ab46a06)
2020-07-17 14:07:34 -07:00
jean-pierre charras fd55b7b4ed 3D viewer: use the full board bounding box to define the visible area.
From master, commit eab98eee.
2020-07-07 11:46:46 +02:00
Ian McInerney 5bca5e2d77 eeschema: Only warn user about off-grid pins if the position has changed
(Cherry-picked from f7156a9d49)

Fixes https://gitlab.com/kicad/code/kicad/issues/4673
2020-07-03 03:02:03 +01:00
Jeff Young ee96937fd4 Scale polygon drawing guides with zoom.
Fixes https://gitlab.com/kicad/code/kicad/issues/4769

(cherry picked from commit e26625fc99)
2020-07-01 17:34:35 +01:00
jean-pierre charras a370d69542 Gerber plotter: Better object attributes handling when plotting a zone
- Clear object attributes before and after plotting a zone.
 It avoid using previously defined object attributes when plotting the next
 zone, and using therefore incorrect attributes.
- Add aperture attribute to filled zone solid polygons (regions in Gerber)

From master branch
2020-06-28 13:14:06 +02:00
Seth Hillbrand 24aad2eed4 Fix order-of-ops issue in sim plot
(cherry picked from commit 67bd49b4a8)
2020-06-27 20:00:17 -07:00
Frank Severinsen 910605cc7d Fix text rotation after flip
fixes https://gitlab.com/kicad/code/kicad/-/issues/4407

(cherry picked from commit 9cf1e61d8a)
2020-06-27 21:49:15 -04:00
Seth Hillbrand 7194e25bba pcbnew: Allow slow ratsnest to turn off
Depending on where you move the selection, the slow ratsnest might turn
on.  This prevents that setting from being sticky, reverting to smooth
movement.

(cherry picked from commit a893d19d26)

Fixes https://gitlab.com/kicad/code/kicad/issues/1909
2020-06-24 17:27:39 -07:00
Seth Hillbrand 7f287cb8f9 Remove delauney computations from dynamic ratsnest
Avoids additional calculations on movement by using cached ratsnest for
internal nets and keeping bicolored line calc for others.

Fixes https://gitlab.com/kicad/code/kicad/issues/1865

cherry-picked from 104ff29e5f
2020-06-22 20:42:12 -07:00
jean-pierre charras a0ce1491d9 Gerber plot solder mask margin: use new algo from master branch to avoid
merging pad shapes when the min width mask is not 0.

Keeping pad shapes clearly identified in Gerber files is mandatory,
so the initial algo that merged shapes in some cases was not good
from this point of view.
2020-06-21 20:47:58 +02:00
jean-pierre charras 26035d23fe Pcbnew, DIALOG_PLOT_BASE: better warning message about non null solder mask margins. 2020-06-21 20:42:37 +02:00
jean-pierre charras 835debe75e Gerber plot solder mask layer: prepare new algo to avoid merging pads in zones 2020-06-18 17:54:00 +02:00
jean-pierre charras b482deb8b0 Fix a incorrect code after a old other code change. 2020-06-18 12:53:06 +02:00
Ian McInerney 76fd1e6f5a Include the ngspice library in the bundle fixup command
This is a patch that has been carried in the kicad-mac-builder
repository that is being upstreamed into the main codebase.

(cherry-picked from 0bfe4130f5)
2020-06-15 22:47:43 +01:00
jean-pierre charras abb45fbe45 Gerber plotter: better choice of aperture attributes in internal layers.
From master branch
2020-06-14 18:18:20 +02:00
jean-pierre charras 567ce48cc1 panel lib tables: avoid crash when deleting the last entry in list.
From master branch
2020-06-14 17:51:27 +02:00
jean-pierre charras 56a17b4e68 Gerber plotter: ensure the gerber region for a round rect pad is always closed.
Due to rounding issues, sometimes (especially for rotated pads)
the region (4 segments+4 arcs) was incorrectly closed
1 unit (nanometer) mismatch between start point and end point.
Although it does not create bad shape, its breaks the round rect pad
identification in CAM tools. start point and end point are now the same.

From master.
2020-06-12 10:54:09 +02:00
jean-pierre charras c027e72439 Solder mask clearance default value: set default to 0, taking advice from
both Ucamco and Eurocircuits.
Update message in plot dialog about best solder mask clearance value.
Show a warning message in plot dialog if these values are no 0.

From master branch.
2020-06-07 15:52:12 +02:00
Seth Hillbrand 25b8da8e3b PNS: Use segment shape for all oval pads
Instead of calculating a simple polygon for the oval pads that are
rotated, we use a rotated segment.

Fixes https://gitlab.com/kicad/code/kicad/issues/4604
2020-06-04 20:28:59 -07:00
Seth Hillbrand 5b47d1a910 Prevent multiple kiway from loading simultaneously
Each KIWAY_PLAYER has some initialization elements that may take time
before the frame is raised.  If handling is returned to the UI during
that load, we can cause reentrant issues for players.

Fixes https://gitlab.com/kicad/code/kicad/issues/4284

Fixes https://gitlab.com/kicad/code/kicad/issues/3743
2020-06-04 16:37:35 -07:00
Jeff Young a844c3043c Fix offset issue when pad edited from board instead of modEdit.
(cherry picked from commit 7db4a3f702)
2020-06-03 14:42:13 +01:00
jean-pierre charras e099a82d15 eeschema: do not propagate text field change to other units for not annotated symbols
Fixes #4602
https://gitlab.com/kicad/code/kicad/issues/4602
2020-06-03 08:52:48 +02:00
Jeff Young b681af4556 Check for duplicate field names.
Fixes https://gitlab.com/kicad/code/kicad/issues/4219

(cherry picked from commit 5d493abea7)
2020-06-02 22:57:29 +01:00
Jeff Young 78d66a9ac3 Don't allow the pad preview canvas to become too large.
Also offset canvas with pad so that hole stays in centre.

Fixes https://gitlab.com/kicad/code/kicad/issues/4185

(cherry picked from commit 3bd4c0c5dc)
2020-06-02 22:57:05 +01:00
Jeff Young bfe4d9f3f4 Cherry pick fix for 4549.
Fixes: lp:4549
* https://gitlab.com/kicad/code/kicad/-/issues/4549
2020-06-01 21:57:16 +01:00
Jeff Young a02ee3719c Update membership grid when a netclass name changes.
Fixes https://gitlab.com/kicad/code/kicad/issues/4596
2020-06-01 21:57:16 +01:00
jean-pierre charras 542f713678 Fix PCBnew crash when show local ratsnest and selecting a footprint with no pads
From master, commit e3c3dae
2020-06-01 09:22:29 +02:00
jean-pierre charras 2395c6fdaa toolbars_lib_view.cpp and toolbars_libedit.cpp: do not
recreate comboboxes when clearing toolbars. Clearing toolbars delete only
tools, not other widgets. recreating comboboxes creates strange cosmetic issues.

From master, commit 598ed8b39.
2020-05-30 15:57:18 +02:00
Steven A. Falco c7f02d5e51 Add Python 3.9 compatibility
Taken from downstream Fedora commit.

Original author info:
Charalampos Stratakis <cstratak@redhat.com>  2020-05-28 12:26:59

Downstream commit: a2677c159ad529

(cherry-picked from 7fd661f06b)
2020-05-29 22:13:26 +01:00
Érico Rolim 55a726e933 Fix sg_version detection for cross compilation
Fixes https://gitlab.com/kicad/code/kicad/issues/4525

(cherry picked from commit e9e72bd8e4)
2020-05-28 13:19:10 -04:00
jean-pierre charras 601633347c Pcbnew: fix a crash when trying to edit a pad in the board editor 2020-05-28 09:51:06 +02:00
Michael Kavanagh 182973c0ee NPTH pads can have the hole offset from centre
Fixes https://gitlab.com/kicad/code/kicad/issues/3671

(cherry picked from commit e800c47406)
2020-05-26 13:35:38 -04:00
Wayne Stambaugh a16e9ac76a Symbol editor: fix crash when editing new symbol value field.
Fixes https://gitlab.com/kicad/code/kicad/issues/4471
2020-05-21 16:46:00 -04:00
emC5RgViIK 66f70e5da6 (Cherry-picked from 47297402d3) 2020-05-15 12:37:41 +01:00
Simon Richter 5a187c6ca8 Make sure that Ninja knows the version header (fixes #4209)
This is required, because Ninja otherwise doesn't properly rebuild after
updating the version string header file.

Because BYPRODUCTS requires CMake 3.2, bump the minimum version and remove
now unused compatibility code for older CMake versions.
2020-05-15 10:51:12 +00:00
Jeff Young c6042100f9 Add ~ processing in env vars.
Fixes https://gitlab.com/kicad/code/kicad/issues/1829

(cherry picked from commit 3a9746c657)
2020-05-14 00:35:10 +01:00
jean-pierre charras fde7ae4d19 Pcbnew: fix a crash due to use of invalid pointers after a list modification
from master branch, fix bug #4409
2020-05-13 14:04:20 +02:00
Jeff Young e37e13e700 If more than one text matches by text try layer and then position.
Fixes https://gitlab.com/kicad/code/kicad/issues/4187

(cherry picked from commit 8df5f70c4a)
2020-05-13 00:14:40 +01:00
Jeff Young d22003578e Use standard OK/Cancel paradigm rather than Apply/Cancel.
Apply/Cancel puts the buttons in a different order on some platforms.

Fixes https://gitlab.com/kicad/code/kicad/issues/4332

(cherry picked from commit 52d1c93777)
2020-05-13 00:04:51 +01:00
Jeff Young 52139cf0c4 Don't resync the screen before we've changed it back.
Fixes: lp:4382
* https://bugs.launchpad.net/kicad/+bug/4382
2020-05-12 22:58:15 +01:00
Jeff Young 37b723d8ae Fix pad name increment to use last edited pad.
Fixes https://gitlab.com/kicad/code/kicad/issues/1882

(cherry picked from commit 56946f4db1)
2020-05-12 22:58:15 +01:00
Jeff Young aec3649524 Add FocusOnLocation for second items in ERC markers.
Fixes: lp:4237
* https://bugs.launchpad.net/kicad/+bug/4237
2020-05-12 22:58:15 +01:00
Jeff Young 36d716bb50 Update toolbars when changing units.
Fixes: lp:4249
* https://bugs.launchpad.net/kicad/+bug/4249
2020-05-12 22:58:15 +01:00
Wayne Stambaugh f61c692929 Eeschema: fix partial schematic load bug in the legacy plugin.
Move the hierarchical sheet loading outside of the try exception block
so that any sheets that were loaded when a schematic file load fails
are loaded rather than skipped.  This allows more of the schematic to
be loaded when any parser errors occur.

(cherry picked from commit 1a8082c6d6)
2020-05-11 16:45:11 -04:00
Wayne Stambaugh 3f717f3baf Eeschema: fix sheet bug in schematic editor drawing tool.
SCH_SHEET objects can only have another SCH_SHEET object as a parent
or nullptr for the root sheet so overload EDA_ITEM::SetParent() to
prevent the parent from being set to another type of object and add
some checks to the root sheet code just in case someone gets clever
and attempts to bypass the overloaded SetParent() call.

(cherry picked from commit fa57c8a570)
2020-05-11 16:33:40 -04:00
Wayne Stambaugh ffc95090aa Begin version 5.1.7 development. 2020-05-11 14:47:14 -04:00
Wayne Stambaugh 2eaa9236f2 Tag release version 5.1.6. 2020-05-11 14:27:08 -04:00
Jeff Young e4bab37b62 Don't try and run drawing tools in ModEdit with no module selected.
Fixes: lp:1836673
* https://bugs.launchpad.net/kicad/+bug/1836673

(cherry picked from commit 02eb1d2c62)
2020-05-09 17:41:56 +01:00
Jeff Young 105c9c71ee Don't let point editor interrupt other operations.
Fixes: lp:1832416
* https://bugs.launchpad.net/kicad/+bug/1832416

(cherry picked from commit ae8daee83c)
2020-05-09 17:41:56 +01:00
Jon Evans e135229ca6 Don't try to draw a zone that has no outline
Fixes #4352

(cherry picked from commit 366673d995)
2020-05-07 17:54:00 -04:00
jean-pierre charras 97dea6ede5 Gerbview: Fix a crash Don't try to close an empty polygon on G37 command.
Can happens with malformed Gerber files.
From Master, commit 528ebf8.
2020-05-07 09:55:13 +02:00
jean-pierre charras d871a92d1c library viewers: fix a focus issue that prevent using arrow keys in lib or fp lists.
Once the gal canvas hsad the focus, it was not possible to use arrow keys in library
or symbols or fp lists even after clicking on an item.

This focus issue is now fixed.

From the fix in Master
2020-05-03 20:23:41 +02:00
jean-pierre charras a152aa125b Footprint editor: fix a crash when a graphic item is selected and the
measurement tool is active and closing the frame, or selecting a new footprint.
I am guessing it was a use after delete data.

Fixes #4302
https://gitlab.com/kicad/code/kicad/issues/4302
2020-05-03 09:03:32 +02:00
jean-pierre charras 4e217d4028 SVG plotter: fix some issues: incorrect bitmap size and missing lines in header.
From master branch.
2020-04-24 16:52:50 +02:00
Jeff Young e5da7a4606 Fix via printing.
LAYER_VIAS needs to get set for them to print at all, and GetLOD
needs too look at the view layer visibiilties, not the board layer
visibilities.

Also implements a more pad-like strategy for printing blind/buried
vias when printing one layer per page (where the top/bottom arcs
don't make sense).

Fixes https://gitlab.com/kicad/code/kicad/issues/1938

(cherry picked from commit dce42612d3)
2020-04-20 20:29:05 +01:00
Jeff Young faace3090c Add specific selection updating when adding 3D models.
This keeps us from being at the receiving end of wxWidgets' vagaries.

Fixes https://gitlab.com/kicad/code/kicad/issues/3760
2020-04-19 22:43:32 +01:00
jean-pierre charras d3e2345f94 Dxf import: fix a bug that disable import of data inside blocks 2020-04-19 13:32:59 +02:00
jean-pierre charras a3e087ab51 Pcbnew: Fix crashes when delete footprint text in some cases.
Fixes #4221
https://gitlab.com/kicad/code/kicad/issues/4221
2020-04-18 20:00:26 +02:00
jean-pierre charras 3a614a8ea1 Legacy plugin: fix incorrect number of copper layers after loading a .brd file. 2020-04-18 19:58:45 +02:00
Marcus Comstedt 9cb60dcdf5 Cairo GAL: fix incorrect use of pixman formats
Fixes https://gitlab.com/kicad/code/kicad/issues/3970

(cherry-picked from 55ac575a88)
2020-04-15 01:29:50 +01:00
Jon Evans af6db68816 Defer image surface destruction until next paint
Fixes #4043

(cherry picked from commit 23c1baae8e)
2020-04-15 01:18:55 +01:00
Adam Wolf 305ed0b65a For macOS, fix KICAD_BUNDLE_LIBS in ogltest.
(Cherry-picked from e143ecbf40)
2020-04-10 20:09:34 +01:00
jean-pierre charras 263efb41e8 Gerbview: fix incorrect rendering of oval vertical standard aperture with hole.
Fix also incorrect display of dcode size in toolbal: was Y size, X size.
Now is X size, Y size as expected.

From master branch
2020-04-10 16:26:38 +02:00
jean-pierre charras d6312c7b92 Gerbview: add a error message for invalid files missing G74 or G75 commands.
They are mandatory to read arc coordinates.
2020-04-10 13:38:11 +02:00
Jeff Young b31af4891d Be smarter about determining if there are modules in the selection list.
The old algorithm would delete modules if another module was in the
list, which was not the intention.

Fixes https://gitlab.com/kicad/code/kicad/issues/4175
2020-04-09 00:07:07 +01:00
Adam Wolf 0ba08f57f2 Add macOS KICAD_BUNDLE_LIBS search path for bundle fixup.
(cherry-picked from ac20428b82)
2020-04-03 01:39:31 +01:00
Wayne Stambaugh a2d7881afe Fix cherry pick error on previous commit. 2020-04-02 16:09:25 -04:00
Wayne Stambaugh d79e598bf8 Eeschema: fix symbol cache library look up bug.
Use an underscore character instead of a semicolon between the library
ID library nickname and symbol name in library ID search strings when
looking up symbols in the cache library since that is how they are saved
when creating the cache library.  This fixes rescuing missing symbols
from the cache when they have been removed from the original library and
preventing a broken symbol link indicator from being shown when a symbol
is removed from the library.

Add some defensive testing to make sure the library passed to function
SchGetLibPart() is actually the cache library.

(cherry picked from commit f6d7ef367d)
2020-04-02 16:04:59 -04:00
jean-pierre charras a6a39cb842 Gerber plotter: Non horiz or vertical oval pads: better plot output:
These pads were plotted as a segment. This is not the right way:
Pads must be flashed or plotted as regions, not painted.
They are now plotted as Gerber regions round rectangle pads.
These regions are similar to flashed pads.

From Master branch, commit de7154e8e.
2020-04-02 19:50:59 +02:00
Wayne Stambaugh 5d0883c0e4 Eeschema: fix rescue multiple unit symbol bug.
The code that checked for pin conflicts to determine if a symbol needed
rescued did not check either the pin convert setting so it was possible
for a pin from the other convert on symbols that do not have identical
units to appear to not have a pin conflict.  Add tests for pin unit and
convert setting to prevent that from breaking the comparison.  This must
have always been broken.

Fix the symbol preview widget to prevent drawing all symbols on top of
each other (if we need to do this the code will have to be revised) and
also show the convert if valid.

Fix broken symbol cache library when saving alias symbols.

Fixes https://gitlab.com/kicad/code/kicad/issues/3879

(cherry picked from commit e91f1f57dd)
2020-04-02 09:31:25 -04:00
Seth Hillbrand e6d49424cf PNS: Don't link unroutable items
The joint map only works for items that are routable, so don't bother
adding unroutable items as this only takes additional time to process

Fixes #3976 | https://gitlab.com/kicad/code/kicad/issues/3976

(cherry picked from commit 9769e1020b)

Fixes https://gitlab.com/kicad/code/kicad/issues/4143
2020-04-01 08:31:57 -07:00
Seth Hillbrand 72abcd5991 Correct cyrillic 'f' in newstroke
The lowercase greek phi had been used which did not match the cyrillic
f.  We use the variant of phi that includes the full strokes instead.

Fixes #3898 | https://gitlab.com/kicad/code/kicad/issues/3898

(cherry picked from commit 39a45f2a81)
2020-04-01 08:31:14 -07:00
jean-pierre charras 9c2bb85858 3D viewer: fix a minor problem: to many rotations when typing
Shift+z or Shift+y more than once.

From master, commit 00d9e77e
2020-03-31 17:48:50 +02:00
Jeff Young e9b059ee94 Re-implement change from cbef95256b
Fixes: lp:4103
* https://bugs.launchpad.net/kicad/+bug/4103
2020-03-30 20:24:08 +01:00
Ian McInerney 7a913844e2 Fix discrepancy between ASCII and CSV fp pos files
(based on 570ea62b64)

Fixes https://gitlab.com/kicad/code/kicad/issues/3897
2020-03-30 10:42:15 +01:00
jean-pierre charras f8be7e1f57 Gerber X2 format: Set default values to Enable X2 format 2020-03-29 15:37:36 +02:00
jean-pierre charras d5c43c4675 Gerber: fix a minor issue in OBLONG standard aperture: - incorrect (too big) bounding box. - HitTest did not test the exact shape. 2020-03-27 16:19:22 +01:00
jean-pierre charras 85fa6d8025 3D viewer: apply patch from master 04d6ea982.
The 3D viewer does not show the issue on solder paste layer having
negative clearance.
However the bug was here and not seen just because some draw code was different:
The code tried to draw outlines with segments having a negative thickness.
It happens mainly on solder paste layers.
2020-03-27 10:36:14 +01:00
Ian McInerney 6b2a8f54a1 Check for file writability before saving part
This is a 5.1 only fix for this crash. Fixing in master requires
a major refactor of the library writability detection code.

Fixes https://gitlab.com/kicad/code/kicad/issues/3864
2020-03-25 13:23:49 +00:00
jean-pierre charras bd1fb845b1 3D viewer: fix a minor issue in solder paste rect pads:
the solder paste mask clearance was no taken in account
for rect and trap shapes.
2020-03-25 13:47:48 +01:00
jean-pierre charras 9c64c9af5d Kicad manager: fix an issue on Windows when killing Kicad.
For some obscure reason, on Windows, when killing Kicad from the Windows task manager
if a editor frame (schematic, library, board editor or fp editor) is open and has
some edition to save, OnCloseWindow is run twice *at the same time*, creating race
conditions between OnCloseWindow() code.

Fixes #4072
https://gitlab.com/kicad/code/kicad/issues/4072
2020-03-25 09:51:12 +01:00
jean-pierre charras 1057eceb2f Gerber plotter: plot round rectangle pads using a region with arcs.
Previously, the region was a usual polygon with arc approximated by segment.
Using a region with arcs is a better way because it allows CAM tools to
identify this region as a round-rect pad.

Similar to master branch, commit 9cb3333d05.
2020-03-22 08:31:25 +01:00
Wayne Stambaugh 445bc75319 3D Viewer: fix broken check for write image permission check.
Fixes https://gitlab.com/kicad/code/kicad/issues/4081

(cherry picked from commit d8e99dc5be)
2020-03-21 17:20:04 -04:00
jean-pierre charras 4fb7ee02cd Kicad: unzip project: fix issues: - files with no extension were skipped. - subdirs were ignored. 2020-03-21 14:08:38 +01:00
Wayne Stambaugh ad11b7ebd0 3D viewer: fix double warning attempting to save screen shot file.
Fixes https://gitlab.com/kicad/code/kicad/issues/4028.

(cherry picked from commit fc20f9f0b2)
2020-03-16 13:09:02 -04:00
Seth Hillbrand 5d9bda6f97 Partial revert of 134a7ba85
The margin fix prevented some schematics from printing.  Reverting in
favor of transitioning to the Cairo print base in eeschema

(cherry picked from commit 9de7547c25)
2020-03-13 11:54:09 -07:00
jean-pierre charras 54be07c17d Pcbnew: Set default solder mask min size to 0.
When the solder mask min size is > 0, pads are no longer flashed or regions items.
Good Gerber files need pads flashed or regions items.

Non 0 solder mask min size is reserved to special cases (home made PCBs for instance)

From master branch.
2020-03-12 20:47:21 +01:00
jean-pierre charras 2c7ab3a28e Pcbnew, Gerber output: always generates Aperture Attributes.
Previously, for historical reasons, they were added only if
Include Netlist Attributes option was on.

But Aperture Attributes have nothing to do with Netlist Attributes, and good
Gerber files must include them.

From master branch
2020-03-12 17:00:55 +01:00
jean-pierre charras 3cc3c1bbd3 Zones: fix a crash when adding a zone cutout to a zone having already holes
From master branch
2020-03-12 14:49:36 +01:00
jean-pierre charras ddedf2e046 Annotate dialog: fix incorrect list of changes in complex hierarchies
Previously, to list changes, the Reference field was used in comparisons.
In complex hierarchies, this is incorrect: the Reference field contains
only the last displayed reference, not the reference of a given sheet.

The comparison uses now the sheet paths for ref and unit selection.

From a similar fix in master branch.
2020-03-09 18:28:39 +01:00
Seth Hillbrand a60c339f85 PCAD: Handle mirrored text
Mirrored text rotates clockwise in the mirror, so we need to invert the
sign for aligning mirrored PCAD text

Fixes https://gitlab.com/kicad/code/kicad/issues/3992

(cherry picked from commit 058fb3afa1)
2020-03-05 15:29:47 -08:00
Michael Kavanagh ce2c5d6528 Remove empty choice in Via type dropdown
Fixes https://gitlab.com/kicad/code/kicad/issues/3968

(cherry picked from commit 265c1663f9)
2020-03-03 14:21:21 -08:00
Seth Hillbrand fd81f70355 Drop invalid arcs on footprint load
In the case where the footprint arc has a non-normal angle, we cannot
represent this in pcbnew and it corrupts the gerber output.  Therefore
we drop the invalid arc and continue to load the footprint/board.

Fixes #3918 | https://gitlab.com/kicad/code/kicad/issues/3918

(cherry picked from commit 3e0ff72720)
2020-03-02 15:59:35 -08:00
Seth Hillbrand 100bb7c6ca Set Module Editor flag for tools
The commit takes the module edit flag when resetting the tool.  All
tools should reset this flag when we setup the Module editor.

This is slightly different in master and v5, so  this is a rework of
7bdf71abc

Fixes #3973 | https://gitlab.com/kicad/code/kicad/issues/3973
2020-03-02 12:45:47 -08:00
Seth Hillbrand 1ffcedd9d4 libedit: Fix speed of lib check
The symbol check output the HTML message for each item.  This is _very_
slow and can lock the system reponsiveness.  Changing to a queue/flush
method is much faster

cherry-picked from 245b778454
2020-02-28 08:50:05 -08:00
Ben Dooks fc1f713106 Fix issue with DRC for through hole being applied to SMD pads
Commit d7272b7f5e fixed the use of
the eagle DRC to change the library pad shapes. This was also
applied incorrectly to SMD stacks.

Remove the references to m_rules in packageSMD() and the code
that deals with them. eagle 7.7 does not have any SMD pad options
other than rectangle with rounding.

(cherry picked from commit 070c6b8ce0)
2020-02-27 09:01:42 -08:00
Seth Hillbrand 83c3a78e6d pcbnew: Avoid wx scaling error
When drawing to a scaled DC, the window doesn't reflect the expected
size if scaled after.  This causes elements drawn on the edge to reflect
back into the drawing area instead of being cut off.

We can simply scale our own values to avoid this issue.

Fixes #3849 | https://gitlab.com/kicad/code/kicad/issues/3849

(cherry picked from commit 5b6a4d794f)
2020-02-27 09:01:18 -08:00
Ian McInerney e6a3e7024d Also verify that the .dcm is writable when saving library
Fixes https://gitlab.com/kicad/code/kicad/issues/3946

(cherry-picked from b2cc454878)
2020-02-26 19:38:30 +00:00
jean-pierre charras d62fde0d79 Pcbnew, Fix issue when trying to create a drawing (line,circle,arc,polygon):
Display a error message if no free graphic layer is enabled, to switch from
a copper layer.

Fixes #3916
https://gitlab.com/kicad/code/kicad/issues/3916
2020-02-24 19:59:07 +01:00
Jon Evans a70cf464d6 Check if scaling factor has changed when top-level window is moved
Fixes #2592

(cherry picked from commit 712ae5a953)
2020-02-23 15:55:05 -05:00
Jon Evans 546260348d Rework window size and position fixing code
Fixes #2624
Fixes #3888

(cherry picked from commit 96da45f12f)
2020-02-23 15:55:05 -05:00
jean-pierre charras 693aec949c Gerbview: Gerber attributes display: fix incorrect attributes deletion.
The Gerber attribute deletion command (%TD,xxx) always cleared all attributes,
instead of clearing xxx attribute.
Therefore some attributes were not always displayed.

From master branch, commit 7206b567
2020-02-23 10:05:00 +01:00
jean-pierre charras 5c7ac1bb7e ZONE_FILLER: fix incorrect thermal clearance of pads having "not in zone" option. Pads inside a zone of the same net having the "not in zone" option have a "antipad" clearance. The value in this case is the biggest between zone clearance and thermal clearance (the net clearance is 0 betwen items of the same net)
However a bug created a incorrect value, due to the fact the minimal zone width
was incorrectly taking in account in calculations.
2020-02-17 17:12:24 +01:00
jean-pierre charras 8862752523 Remove a fix committed in 6b78fdf by mistake. 2020-02-17 13:00:56 +01:00
jean-pierre charras 201c380925 QA tests: remove deprecated headers, already not used in master branch. 2020-02-17 12:58:04 +01:00
jean-pierre charras c7230a6f77 eeschema: fixes related to translated and not translated field names.
When searching for fields, the code was sometimes comparing
translated and not translated names. This is an issue for mandatory fields,
in non English languages.

From master branch.
2020-02-17 12:26:51 +01:00
jean-pierre charras 6b78fdf822 LOCALE_IO: replace the call to setlocale by a call to wxLocale to switch to "C" locale.
Previously we call only setlocale( xx, "C" ), but it was not enough on Windows.
Now we call wxLocale("C")
wxLocale calls setlocale, but also make some others initialization in wxWidgets.
It fixes some issues related to comma versus point as fp separator.
Especially wxWidgets warnings are no longer thrown, and a one case of incorrect
conversion is fixed.
However, wxLocale( "C" ) also switches the current translations to English, so
loading files can have a slightly different behavior
2020-02-17 09:14:18 +01:00
Jon Evans 3cb326e426 ADDED: Expose GetBuildVersion and GetBuildDate to Python
(cherry picked from commit 8fb72d8290)
2020-02-15 09:59:43 -05:00
jean-pierre charras d3f9332372 Kicad manager: Avoid crash when calling configure libraries from main menu,
when _eeschema.kiface or _pcbnew.kiface is not found.
Happen mainly when running Kicad from build tree.

From master branch.
2020-02-11 16:15:19 +01:00
jean-pierre charras be0f6a6af2 Fp editor: fix: Reference and Value default values aren't saved in Footprint Editor preferences
Fixes #3889
https://gitlab.com/kicad/code/kicad/issues/3889
2020-02-11 15:48:05 +01:00
Seth Hillbrand 25aa233cef eeschema: Temporary fix for GTK printing offset
The full fix will be Cairo printing in v6

Fixes https://gitlab.com/kicad/code/kicad/issues/1907

(cherry picked from commit 134a7ba85d)
2020-02-10 09:07:21 -08:00
Jeff Young 5fdc424202 Don't report Eagle errors on the Unrouted layer.
Fixes https://gitlab.com/kicad/code/kicad/issues/3398
2020-02-05 22:20:16 +00:00
Jeff Young 9b74bb5c92 Remove preferred layer disambiguation for multiple modules.
The preferred list isn't actually in use anymore at this point, so
it currently has no effect other than to mess things up since we
aren't keeping track of which modules have been rejected when we
check the module count.

Fixes https://gitlab.com/kicad/code/kicad/issues/3721

(cherry picked from commit d02c0da3ab)
2020-02-05 22:20:16 +00:00
Jeff Young 8bf8a649c8 Adjust justified text for mirroring and rotation.
Fixes https://gitlab.com/kicad/code/kicad/issues/3737

(cherry picked from commit 2507f985ad)
2020-02-05 22:20:16 +00:00
Ian McInerney 7ba8d8b608 Revert eeschema highlighting changes
This reverts commit 366d4d7b0b.
This reverts commit 8b3c0a941c.

Fixes https://gitlab.com/kicad/code/kicad/issues/3866
2020-02-05 11:51:46 +00:00
Drew Fustini e35328fece Update copyright year in About dialog to 2020
(Cherry-picked from f359892de3)
2020-02-04 21:42:23 +00:00
Ian McInerney 366d4d7b0b eeschema: Ignore the highlight flag when responding to dbl click
Fixes https://gitlab.com/kicad/code/kicad/issues/3855
2020-02-03 21:41:03 +00:00
jean-pierre charras 3af1e75084 Gerber plots: Add initial G01 command to the header,
to ensure linear interpolation mode.
To avoid issues, an interpolation mode must be set before first D01 command.

From master branch.
2020-02-03 17:56:02 +01:00
jean-pierre charras dabd80fe4c Dxf importer: fix issue when importing some "degenerated" splines.
(From master, commit 8f3e8cf)
Sometimes a dxf curve is a "degenerated" bezier curve having only 3 points.
(a control point is at same location as a end point)
This commit fix incorrect import of these curves.

Fixes #3845
https://gitlab.com/kicad/code/kicad/issues/3845
2020-02-03 12:49:45 +01:00
Ian McInerney cb711a648f Fix layout in color dialog on GTK
Don't initially set the minimum widget size, and instead let it be
computed at launch.

Fixes #2617

(Partial cherry-pick of 4f82939384)
2020-02-02 15:40:42 +00:00
Karl Zeilhofer 5b58dbc980 Fixes dangling ends and rotation when labels/texts are converted into each other
CHANGED: Eeschema: Preserve text justification when switching text types

Closes https://gitlab.com/kicad/code/kicad/-/merge_requests/86
2020-02-01 16:08:34 +00:00
easyw 8b3c0a941c Highlight eeschema symbol on left click
CHANGED: Highlight eeschema symbol on left click

Closes https://gitlab.com/kicad/code/kicad/-/merge_requests/83
2020-02-01 16:08:19 +00:00
Seth Hillbrand 3ce29a3d7e Eeschema: Add bit that was missing from commit 7ac83ac64
This part of the check removes recursive sheets from the schematic when
loading and notifies the user that their schematic has been repaired.

(cherry picked from commit 128ec782dd)
2020-01-27 09:43:07 -08:00
Seth Hillbrand dc3c6b2f39 Check recursion before appending
We need to ensure that the appended sheet does not already exist in the
parent hierarchy.  We do this for new sheets but need to check for
existing ones as well.

Fixes #3806 | https://gitlab.com/kicad/code/kicad/issues/3806

(cherry picked from commit 7ac83ac64d)
2020-01-27 06:31:16 -08:00
Ian McInerney 1cbee4c504 gerbview: Add default filename to export to pcbnew function
Some platforms (such as Linux) don't automatically append file
extensions, so we should ensure extensions are correct and the user is
prompted accordingly.

Fixes https://gitlab.com/kicad/code/kicad/issues/3817

(Cherry-picked from 88e0ef548d)
2020-01-26 16:26:03 +00:00
qu1ck 798e4c288a Fix polygon shape move
Move vector should not affect start/end points as they are assumed to
always be 0,0. Polygon is defined by outline only.

(cherry-picked from 32674ef360)
2020-01-23 00:40:33 +00:00
Seth Hillbrand ac39e32bc9 Recognize subckt blocks in spice
Spice lines defining circuit elements are contained in a .subckt ..
.ends block.  The intervening lines should be exported to the netlist as
well as the control lines.

(cherry picked from commit d9eaff1c99f4c6664e23f8995062cf34f92dbc6c)
2020-01-17 18:58:27 -08:00
Seth Hillbrand 52da7f931b pcbnew: Check before reading/writing cache
The open/create calls can fail so we need to account for this before
using the result that assumes success.

(cherry picked from commit 88729de68553427c7f2ca2d32cad46f959b8cc3c)
2020-01-17 18:34:28 -08:00
Ian McInerney fcb6f814de Fix macos plist version string generation
Generate these resource files similar to how it is done one Linux.

Fixes mac-builder issue https://gitlab.com/kicad/packaging/kicad-mac-builder/issues/275

(Cherry-picked from 25a302758e)
2020-01-18 01:44:01 +00:00
Seth Hillbrand 9e6b56d783 PNS: Detect collisions including newline width
The new line collision search uses BBox() to check for colliding
objects.  BBox in the SHAPE_LINE_CHAIN did not include width as the
chains were assumed to be zero-width.  This is not the case for
PNS::LINE elements.

We mostly don't notice this because DRC checks for SEGMENT collisions
but it becomes obvious/annoying when we cannot place a track for unknown
reasons and the snap-back doesn't take line width into account.

Fixes #3776 | https://gitlab.com/kicad/code/kicad/issues/3776

(cherry picked from commit fe15511d38f2e6ffb293e2e708f8e3ed89c1a4d3)
2020-01-17 11:26:02 -08:00
Seth Hillbrand 923dad6ca8 PNS: Modify MarkObstacles logic to select shorter
When routing where we hit multiple obstacles, we choose the shortest
path to allow overlapping hits to choose the shorter path, thus giving a
better chance of returning true for the DRC-compliant path.

Fixes #3773 | https://gitlab.com/kicad/code/kicad/issues/3773

(cherry picked from commit 38f13ef481cd2e5cf560b921bcaabf9cdc7d00fb)
2020-01-16 19:58:19 -08:00
Ian McInerney 9f17d91b32 Fix return type in KIDIALOG
It was returned as a bool for some reason...

(Cherry-picked from 1f8611f1988f3165d49dc3039ad9b42947b57f01)
2020-01-15 18:30:24 +00:00
Mark Roszko 2bcb04a3b1 KIDIALOG should ignore "cancel" for the do not show again option.
CHANGED: Do not remember "do not show again" when cancel button is pressed

Fix #3734

(Cherry-picked from 3ae784d97fb50bc70cc49e27b9f424958e583257)
2020-01-15 18:26:20 +00:00
Ian McInerney a530b600b8 Smoothen rotation in 3D viewer when crossing the 0-2pi line
Rotating to 0 when above pi would result in the board spinning back
through pi to get there. This led to jarring motion.

Also fix an issue added in b6f64815 where the board would rotate
2pi when crossing over the 0-2pi boundary.

(Cherry-pick of 4fc9b4e5ab63fa192ec2a7d40574f614b318668c)
2020-01-15 18:10:46 +00:00
jean-pierre charras d494a2bee2 3D viewer: normalize rotation angles between -2_PI and 2_PI.
Fixes #3761
https://gitlab.com/kicad/code/kicad/issues/3761

(Cherry-pick of b6f64815f4)
2020-01-15 16:30:41 +00:00
Ian McInerney 6a027662ae Update Linux appdata file and CMake version strings
CHANGED: Update the Linux appdata file to include new tags

* Include version tags (and others) in the appdata file
* Refactor the version string generation to clean it up

Cherry-pick of:
3370e89967
e54c954aed
2020-01-15 16:23:22 +00:00
Ian McInerney 577bb7bf31 Update AUTHORS.txt with changes from master branch
Cherry-pick of:
8fcd59ebda
037e6bc006
0857a1f5dc
07c6cfdc38

Closes !64
2020-01-15 16:17:19 +00:00
Ian McInerney df664bd55f Don't tie generic validators to a specific field
(Partial cherry-pick of 15cd13ba6e)

Fixes #3667
2020-01-15 16:12:39 +00:00
Seth Hillbrand 8a2705f81f PNS: Assume the current line is a base before optimizing
We use the cost of the current line before trying to improve the pad
breakout cost when optimizing the smart pads

Fixes #3759 | https://gitlab.com/kicad/code/kicad/issues/3759

(cherry picked from commit 52bfdb9703)
2020-01-12 11:13:19 -08:00
Seth Hillbrand fcaf11422a Fix bitmap clipping
When printing (using DC context) the bitmap will clear the full screen
unless the clipping region is set to the image itself.

Addresses KSC ticket 126

Fixes #1877 | https://gitlab.com/kicad/code/kicad/issues/1877

(cherry picked from commit 195c3d074b)
2020-01-11 10:00:57 -08:00
Seth Hillbrand 3444409554 pcbnew: Fix polygon comparison () for end
This is a v5-only fix incorporating 2c5876e and 72da237 into the 5
branch to resolve a crash when parsing invalid polygons.

Fixes #3752 | https://gitlab.com/kicad/code/kicad/issues/3752
2020-01-09 17:15:48 -08:00
jean-pierre charras 683c01b301 SVG plotter: fix an issue with mirrored texts. Mirrored texts have a size < 0. Of course, the actual value for the plotter is the absolute value. 2020-01-09 18:24:15 +01:00
jean-pierre charras e2492f773d FILENAME_RESOLVER: fix missing conversion from UTF8 to wide chars.
Fixes #3742
https://gitlab.com/kicad/code/kicad/issues/3742
2020-01-08 10:47:14 +01:00
Ian McInerney 1f3a2dcd1d Fix cherry-pick error
Fixes https://gitlab.com/kicad/code/kicad/issues/3744
2020-01-08 09:41:01 +00:00
Mario Luzeiro 4205cb32c5 3d-viewer, make ortho projection zoom similar as prespective projection
Fixes #1843
Fixes reload of Raytracing when the projection button is pressed.

(cherry picked from commit 2c00540ad6)
2020-01-06 19:33:00 -08:00
Mario Luzeiro 6ab9bdb346 3d-viewer, ray-tracing, do not add coincident segments
Fixes #1946 (lp 1852970)

(cherry picked from commit 518c1df81b)
2020-01-06 13:56:25 -05:00
Mario Luzeiro a4aec1919c 3D-viewer: raytracing, implement multiple shape board.
Fixes #1879 (lp:1820099)
Fixes #2126 (lp:1764039)

(cherry picked from commit 37c3e34486)
2020-01-06 13:55:31 -05:00
Jon Evans 5b97d70d57 Use existing pcb filename for Save As where possible 2020-01-06 10:33:00 -05:00
Ian McInerney eeeb4596c3 Properly escape spaces when opening PDFs on windows
Fixes https://gitlab.com/kicad/code/kicad/issues/2625

(cherry-picked from 20e7fc8a0e)
2020-01-03 19:09:04 +00:00
jean-pierre charras 23853cae14 Try to fix SEG::PointCloserThan(), not working for quasi H or V segments.
Quasi H or V segments are segments having the same x value or y value
(with a + or -1 max diff) for end points coordinates.
The change is a workaround, not really a fix.

Fixes #3711
https://gitlab.com/kicad/code/kicad/issues/3711
2019-12-31 15:59:45 +01:00
jean-pierre charras 87f6f33b37 fix a minor wxWidgets alert. 2019-12-27 20:03:02 +01:00
jean-pierre charras 8c03d1bdde Gerber files: update unicode coding to the 2019 06 Gerber specifications.
In gbr files, not allowed chars are coded using a 16 bit (4 hexa digits)
unicode sequence.
Previously, it was \XXXX and now is \uXXXX escape sequence.

Changes from master branch.
2019-12-27 20:03:01 +01:00
Wayne Stambaugh 7f1c7d808d Eeschema: fix sheet file name case sensitivity test.
Fix overzealous test if the new file name is the same as an existing
file name.

Fix a potential comparison bug due to missing file extension.

(cherry picked from commit b66ecf141f)
2019-12-27 12:08:13 -05:00
Wayne Stambaugh be12aece5b Eeschema: fix sheet file name case sensitivity bug.
Apparently there are some issues with wxString::CmpNoCase() that was
causing the sheet file name case sensitivity test to incorrectly fail.
Converting the name strings to lower case before comparing resolved
the issue.

(cherry picked from commit 773f45aae3)
2019-12-27 12:07:15 -05:00
Wayne Stambaugh d7605f1449 Eeschema: fix multiple sheet file name bugs.
Add missing check for root sheet when searching sheet hierarchies for
already loaded schematics.  This prevents the root sheet from being
omitted when adding new sheets using the root sheet file name.

CHANGED: Make file name tests case sensitive so that schematic sheet
file names on non-Windows systems can be uses as expected.

Warn users when attempting to use schematic file names that only vary
by case sensitivity that doing so will result in a project that is not
portable to Windows.

Fixes lp:1843415

https://bugs.launchpad.net/kicad/+bug/1843415
(cherry picked from commit d4cea0f2b7)
2019-12-27 12:05:59 -05:00
Jon Evans ef80642dec LSET: Prevent assertion in MSW when size is not a multiple of 4
(cherry picked from commit 2ea565473f)
2019-12-26 10:01:44 -05:00
Jon Evans a5622c93d4 Don't try to write fp-info-cache to a read-only directory
Fixes #1890

(cherry picked from commit 80fb3bde56)
2019-12-25 18:48:21 -05:00
Ian McInerney b6f9bfe9a5 pcbnew: Fix cmake to work with no wxPython on macOS
(cherry-picked from bf5dba847c)
2019-12-25 23:23:31 +00:00
Ian McInerney 79954657e2 eeschema: Fix return ID check in annotate dialog
Fixes https://gitlab.com/kicad/code/kicad/issues/3708

(cherry-picked from e6e2cf47fd)
2019-12-25 23:18:31 +00:00
Mark Roszko 35d3f1f72a common: Remove out of bounds and erroenous array access
(cherry-picked from bf32122134)
2019-12-19 11:35:21 +00:00
jean-pierre charras 388d74faf4 Pcbnew: graphic polygon: display the points count, instead of length,
and coordinate origin.
Previously, the meaningless length (always 0) and begin and end (@0,0)
coordinates were always displayed.

From master branch.
2019-12-18 13:21:35 +01:00
jean-pierre charras 0f8747e194 Gerber plotter: modify G02 and G03 commands.
They are now in a specific block and no longer combined with an other
command.
(combining these commands with an other command (D01 or D02) is deprecated)

Fixes #3677 | https://gitlab.com/kicad/code/kicad/issues/3677
2019-12-18 12:30:28 +01:00
Ian McInerney 93f16ba9e3 Update about dialog link to GitLab
(cherry-picked from c31c99abd1)

Fixes #3687
2019-12-17 20:21:59 +00:00
jean-pierre charras bea2d42e8c Gerbview,export to pcbnew: avoid exporting not valid polygons.
Gerber regions are exported as polygons (they are filled polygon).
The fix ensure the polygons are simple and valid.
Invalid polygons crash Pcbnew.

From master branch, commit 25504319.
2019-12-15 14:24:11 +01:00
jean-pierre charras 68d644fd28 P&S router: length tuning tool: fix a crash after trying to tune a track.
It happens on Windows, and wxWidgets 3.1.3. It is created by
PNS_TUNE_STATUS_POPUP instance used in tool. I am pretty sure this crash is
created by the stack switching when managing events, due to some changes in
wxWidgets code.
The fix creates the instance on the heap, instead of on the stack.
This is not the first time I see this kind of issue.

From master, commit 21dd8db
2019-12-12 10:26:27 +01:00
jean-pierre charras f6e33450ff Gerber object attribute: avoid trying to guess if a SMD pad is a BGA pad.
Previously, if a SMD pad was round, itb was seen as BGA pad.
But this is not always true. so use always SMD PAD attribute,
until an explicit BGA pad attribute is added in Pcbnew
2019-12-11 08:55:44 +01:00
Seth Hillbrand 65008c5c0b Eeschema: Check twice before using GAL
The windows display may through an error which we need to catch when
starting GAL under windows.  This is a reimplementation of
e39586e15 which cannot be cherry-picked into v5

Fixes #2620 | https://gitlab.com/kicad/code/kicad/issues/2620
2019-12-10 16:01:59 -08:00
Seth Hillbrand dbfaf568fc Plot SVG embedded
ADDED: embedded image support for SVG files

Fixes #3643 | https://gitlab.com/kicad/code/kicad/issues/3643

(cherry picked from commit fa133f3f5c)
2019-12-08 08:59:01 -08:00
Fabien Corona 58fd6ac03e PCBnew: placing a blind/buried via sometimes incorrectly place a through via.
From master branch commit 36fba5bd7f
2019-12-08 13:31:21 +01:00
Seth Hillbrand 1e64524afb PNS: Allow snap to temp hidden
The IFACE for kicad refers to the board hidden state, not the
temporarily hidden state used by the router.  We allow snapping to items
that have been removed by the temporary router state to provide snapping
to original track location.

Fixes #1827 | https://gitlab.com/kicad/code/kicad/issues/1827
2019-12-07 09:49:59 -08:00
Seth Hillbrand 20a5d8effd pcbnew: Handle intermediate pad on route
The length calculation wanted to find start/end pads but this was
complicated for paths that had a via on the intermediate pad.  Instead
of warning, we calculate the longest path of the three possibilities

Fixes: lp:1838261
* https://bugs.launchpad.net/kicad/+bug/1838261

Fixes #2554 | https://gitlab.com/kicad/code/kicad/issues/2554
2019-12-04 13:46:09 -08:00
jean-pierre charras 8c7e0bcb0a DIALOG_DRC_CONTROL: fix a crash on wxWidgets 3.1.3
Happens when right clicking on an item in displayed lists.
The crash was due to a bug in wxWidgets, and the fix is only a workaround

From commit 5cd7f3fd in master branch.

Also remove duplicate code.
2019-12-03 09:47:42 +01:00
Jeff Young c69080f11e Fix some issues with the previous commit. 2019-12-02 23:33:45 +00:00
Jeff Young 5a48c800ee Make sure that libraries are always sorted consistently.
Fixes #1847481 | https://gitlab.com/kicad/code/kicad/issues/1847481
2019-12-02 21:55:31 +00:00
Jeff Young c6eff4d373 Update local coords when editing EDGE_MODULEs.
Fixes: lp:1853726
* https://bugs.launchpad.net/kicad/+bug/1853726
2019-12-02 20:01:11 +00:00
Seth Hillbrand 5c056c2a3e Fix compile error for old compilers 2019-12-02 09:19:13 -08:00
M.Scholz 61f593f350 Corrects IsDirWritable check
The check for IsDirWritable needs to reference the absolute path to
return correct values.

Fixes: lp:1853421
* https://bugs.launchpad.net/kicad/+bug/1853421

(cherry picked from commit dbb9b5f64f)
2019-11-21 17:25:48 -08:00
jean-pierre charras 6cc7dc7aaa Pcbnew: fix crash on Linux (when opening Edit Spice model in component properties)
It happens when the spice library model shown in dialog is a large file.
Looks like the wxTextCtrl used to displays the library content
creates the crash ( GKT bug?) for large texts.

The fix is to replace this wxTextCtrlt by a wxStyledTextCtrl.
It has advantages (does not crash... and much faster display) and
inconvenients (cannot disable editing).

Fixes: lp:1853161
https://bugs.launchpad.net/kicad/+bug/1853161
2019-11-21 13:15:14 +01:00
jean-pierre charras 239f040a98 Fix minor wxWidgets alert (wxWidgets 3.1.3) 2019-11-20 18:29:11 +01:00
jean-pierre charras 3827c16fde Fix a wxWidgets alert 2019-11-20 10:02:09 +01:00
Fabien Corona e299343807 Pad ratsnest settings initial value
Pad ratsnest settings set to global settings during initilization.

Fixes: lp:1848488
* https://bugs.launchpad.net/kicad/+bug/1848488

(cherry picked from commit 29ce76b4e4)
(slightly modified due to settings structure difference between
master and 5.1)
2019-11-18 22:34:21 +00:00
Fabien Corona 4130ce2b93 Ratsnest default value for tracks and vias
Fixes: lp:1851611
* https://bugs.launchpad.net/kicad/+bug/1851611

(cherry picked from commit 6182133a4e)
(slightly modified due to differences between master and 5.1)
2019-11-18 22:23:00 +00:00
Seth Hillbrand d6acb64514 CMake: Fix OCE/OCC swap
unset() needs to remove the cached variable to get rid of the implicit
version

(cherry picked from commit 365f9224e7)
2019-11-18 21:20:10 +00:00
jean-pierre charras 8e233e2591 Fix compil issue due to a small incompatibility from cherry-picked code. 2019-11-18 09:13:04 +01:00
jean-pierre charras 9cda16220e Gerbview: add parsing of optional Aperture Macro parameter. AMP_CIRCLE primitive has 4 or 5 parameters (last is optional) Reading the optional parameter was missing.
Fixes: lp:1852924
https://bugs.launchpad.net/kicad/+bug/1852924
2019-11-18 09:07:32 +01:00
jean-pierre charras 36acadbd52 DIALOG_PAD_PROPERTIES: fix incorrect pad type for Aperture option.
The aperture option created a Connector pad only on the paste layer.
This is incorrect: the SMD type only is acceptable.
Connector is *only* for edge card connectors.
Moreover, The dialog did not even accept the setting defined by this dialog...
2019-11-17 18:28:08 +01:00
jean-pierre charras 37b6552c42 FIX: add parameter to GAL::DrawCurve to control the curve to polyline
conversion.
Cairo supports curves, but not Opengl, that needs a conversion to polyline.
This control allows optimization in conversion
2019-11-17 18:22:13 +01:00
jean-pierre charras 1903052d79 Bezier curves: replace previous algorithm to convert the curve to segments.
In some cases it was not working well.
Opengl was using an other algo (using the curve properties to create segments)
Now only the OpenGL algo is used,
with optimization to reduce the number of segments.
2019-11-17 18:22:13 +01:00
jean-pierre charras 2b4cfd9a60 Footprint wizard frame: rebuild the parameter grid list after any parameter change. The python footprint wizard can modify other parameters than the one that was changed by user. So the parameter grid list must be updated after every parameter change.
Fixes: lp:1846404
https://bugs.launchpad.net/kicad/+bug/1846404
2019-11-17 18:22:13 +01:00
Fabien Corona decbb65f09 High contrast color for holes in microvias and buried bias
In high contrast mode, the holes of buried vias and microvias were no darkened when not on the active layer.
In high contrast mode, the outer circle of buried vias and microvias were alway darkened.

In high contrast mode, when the selected layer is non visible through-vias are now darkend.

Fixes: lp:1844982
* https://bugs.launchpad.net/kicad/+bug/1844982

(cherry picked from commit 04edc6ceff)
2019-11-15 12:02:47 -08:00
Seth Hillbrand 8e2ca37edc pcbnew: Prevent extra selection
We want to avoid selecting items that are disabled in the item list.
Our standard method is in the GetViewLOD() that performs both size and
visibility.  This extends the check to module text and via.

Fixes: lp:1851133
* https://bugs.launchpad.net/kicad/+bug/1851133
2019-11-14 09:50:39 -08:00
Wayne Stambaugh 8fb6bcc8b1 Begin version 5.1.6 development. 2019-11-14 12:14:16 -05:00
Wayne Stambaugh 2f36c670ff Tag release version 5.1.5. 2019-11-14 12:09:45 -05:00
jean-pierre charras d701c3a480 Gerber plot: fix a minor issue: TF attribute "Drawing" is now "OtherDrawing,Comment" This is due some changes in recent Gerber file format. 2019-11-05 20:15:00 +01:00
jean-pierre charras cd7f3375b2 Add missing code to plot Bezier curves (EDGE_MODULE shape) in footprints 2019-11-05 20:14:48 +01:00
jean-pierre charras 46cd185524 Fix incorrect HitTest in DRAWSEGMENT (bezier curve) 2019-11-05 16:21:45 +01:00
jean-pierre charras e04d82e940 Gerber plot: minor fixes in TO object attributes.
Gerbview: remove a outdated warning about RS274D format.
2019-11-05 14:25:30 +01:00
jean-pierre charras 26d0863921 minor fix in a python script (kicad_netlist_reader.py) Sort lists was incorrectly made. 2019-11-05 14:25:30 +01:00
Jeff Young 37f23fa537 When copying an item it's no longer at the original location and so can't be "locked".
Fixes: lp:1851038
* https://bugs.launchpad.net/kicad/+bug/1851038
2019-11-03 17:43:36 +00:00
Seth Hillbrand 167d408b5e qrcode: Handle Python3 integer promotion
In Python3, all division operators promote integers to floats.  We need
to downcast back to integer for the polygon vertices.

There was also an unhandled overflow in the QR generation that allowed
more than 512 bits to be loaded.  This overflows the type of QR we
generate, so this truncates the input string to 62 bytes ( leaving 12
bits for the checksum )

Fixes: lp:1850223
* https://bugs.launchpad.net/kicad/+bug/1850223

(cherry picked from commit 9bccbaf497)
2019-11-01 14:57:07 -07:00
Jeff Young d4a8ff4872 Backported edit point colour fix from master.
Fixes: lp:1846372
* https://bugs.launchpad.net/kicad/+bug/1846372
2019-10-31 23:35:23 +00:00
jean-pierre charras fb9b12a982 Footprint editor: fix a crash when trying to edit the properties of a footprint not yet in tree (i.e. imported from file)
(cherry picked from commit cee1873fff)

Fixes: lp:1850497
* https://bugs.launchpad.net/kicad/+bug/1850497
2019-10-29 13:13:54 -07:00
Wayne Stambaugh 88a03f1a1d Begin version 5.1.5-rc2 development. 2019-10-25 14:31:02 -04:00
Wayne Stambaugh ba7e400e13 Tag release version 5.1.5-rc1. 2019-10-25 14:24:51 -04:00
Seth Hillbrand 57f0f88552 pcbnew: Treat circular ovals as circles
The oval clearance adds an edge on the 0-length side of a circular oval.
This is not needed and can affect the fill algorithm.  Instead, we treat
round ovals as circles for pad polygons

Fixes: lp:1849846
* https://bugs.launchpad.net/kicad/+bug/1849846
2019-10-25 09:28:09 -07:00
jean-pierre charras 42a0cf6283 PCB_BASE_FRAME::SelectFootprintFromLibTree(): fix annoying issue: the progress reporter was displayed after loading libraries, because it was destroyed too late. 2019-10-25 18:08:02 +02:00
Seth Hillbrand b67acd5ea1 pcbnew: Fix 45° snapping polygons
The constrained draw was constraining the polygon size to fit the
existing points rather than extending the existing points to fit the
user's intent.

This adds a 90° double-joint for the completion polygon that allows the
user to complete common constrained polygons visually based on the
preview with a double-click to finish.

(cherry picked from commit bae50fab9f)

Fixes: lp:1849299
* https://bugs.launchpad.net/kicad/+bug/1849299
2019-10-24 16:05:27 -07:00
Seth Hillbrand 5e2721d2f5 Increase visibility of polygon preview
This set the polygon preview item to wider size and adjusts the draw
order to ensure it remains visible even when antialiasing

(cherry picked from commit ea1c8525ce)
2019-10-24 16:05:12 -07:00
jean-pierre charras 2cd43aee0a Gerber output: fix some (minor) issues related to attributes when plotting polygonal pads.
rect (when not horizontal or vertical), trapezoid and custom shapes are draw as polygons.

The dummy pad used to give attributes is removed, and TO attributes are used in Regions (polygons in Gerber dialect)

This is due to some modifications in Gerber format since the attributes are added in Kicad.
2019-10-24 09:32:40 +02:00
jean-pierre charras fb1570d290 DIALOG_POSITION_RELATIVE_BASE: fix wxWidget alerts 2019-10-23 20:41:00 +02:00
Seth Hillbrand 79972ad4db pcbnew: Fix DXF Import with blocks
BLOCK elements in DXF are re-usable bits that are useful when editing
the file but should not be shown when importing the model.  This skips
all references except those that exist in the default "*Model_Space".
This block is required in each DXF file and cannot be renamed.

Fixes: lp:1790821
* https://bugs.launchpad.net/kicad/+bug/1790821

(cherry picked from commit df3fabfa21)
2019-10-23 11:31:43 -07:00
Ian McInerney 61934c285c pcbnew: Fix deletion of vias in global delete window
Fixes: lp:1847580
* https://bugs.launchpad.net/kicad/+bug/1847580

(cherry picked from commit 3b1817ee32)
2019-10-23 12:25:00 -04:00
Seth Hillbrand a7d554971c eeschema: Pad spice ops to differentiate
The .op command is isolated, so differentiating from .option with a
space will only work if we ensure all commandlines have a space at their
end.

(cherry picked from commit 4004c733c8)
2019-10-23 06:33:10 -07:00
jean-pierre charras e54ea90607 PROGRESS_REPORTER: fix serious bug in its DTOR: the DTOR was calling Destroy. But Destroy() in wxWidgets calls the DTOR.
It can create recursive calls of the DTOR.
2019-10-23 11:29:44 +02:00
jean-pierre charras fda403a079 Fix potential issue 2019-10-21 08:26:22 +02:00
Sylwester Kocjan f2e75c96be eeschema: fixed recognizing SPICE sim directive
(cherry picked from commit 1c01cc001d)
2019-10-20 12:11:38 -07:00
Seth Hillbrand 322eb2b8a8 pcbnew: Commit polygon points to new constrained zone
Adds leader points if they are not already existing in the zone

Fixes: lp:1846028
* https://bugs.launchpad.net/kicad/+bug/1846028

(cherry picked from commit 2e1af66a2b)
2019-10-20 10:31:08 -07:00
Seth Hillbrand 6f71183d0e Revert "kicad2step: scale models"
This reverts commit 5064df4ba2.

There were un-addressed issues with the VRML substitution and concerns
by MCAD folks that ECAD designers should not be allowed to perform this
action.  Full addressing in v6.
2019-10-20 10:06:43 -07:00
Seth Hillbrand 5d852cf6ae pcbnew: Don't limit editing of the polygons
45 deg contraints are not saved per polygon, so don't limit per polygon.
The constraint is only enforced during creation.

Fixes: lp:1847722
* https://bugs.launchpad.net/kicad/+bug/1847722

Fixes: lp:1846029
* https://bugs.launchpad.net/kicad/+bug/1846029

(cherry picked from commit 8f1c1cf298)
2019-10-20 09:31:26 -07:00
Seth Hillbrand 2d1ea1618b pcbnew: prevent assert with first pt
Finding the pt-to-end intersection requires a segment, so check for
multiple points.

Fixes: lp:1846431
* https://bugs.launchpad.net/kicad/+bug/1846431

(cherry picked from commit 70c64d93e4)
2019-10-20 07:41:48 -07:00
Seth Hillbrand 50723d07a6 GAL: Use vector for stroke elements
deque structures have higher overhead than vectors.  Not usually
problematic, but with hundreds of thousands of characters each with only
a few strokes, the overhead becomes dominant.

(cherry picked from commit 6084614371)
2019-10-19 07:28:25 -07:00
Seth Hillbrand 1161562bc8 Remove Yahoo Groups link
Yahoo has discontinued its groups.

See https://help.yahoo.com/kb/groups/SLN31010.html
2019-10-17 15:59:06 -07:00
Seth Hillbrand 0c8b3aaced eeschema: Don't warp before processing right-click
The logic handling the two bug reports attached to this code is now
higher up in the chain.  As it stood, warping before right-click meant
that we cannot affect any point on the wire that is not an endpoint.
2019-10-17 13:49:49 -07:00
Seth Hillbrand b81b7decf6 eeschema: Add junction when breaking overlapping wires
This is the v5 version of 363281dd4.

Fixes: lp:1848450
* https://bugs.launchpad.net/kicad/+bug/1848450
2019-10-17 13:32:14 -07:00
Seth Hillbrand e5463330ef view: Check for viewData in IsVisible()
viewData can be NULL, make sure we verify it before dereferencing.

(cherry picked from commit 5b8661f2ab)
2019-10-15 09:46:47 -07:00
Seth Hillbrand 17c0b3e460 pcbnew: Check all layers for routing snaps
Flipped footprint pads may report their "primary" layer as not the front
layer in high contrast.  We need to check whether the board item for
snaps is visible on the active layers.

Fixes: lp:1847877
* https://bugs.launchpad.net/kicad/+bug/1847877

(cherry picked from commit 07c8596084)
2019-10-15 09:46:39 -07:00
jean-pierre charras 3bc3193805 Fix typo 2019-10-15 17:50:40 +02:00
jean-pierre charras d6db6dedca Gerber file export: avoid duplicate corner when creating polygons (regions in Gerber dialect)
Fixes: lp:1847714
https://bugs.launchpad.net/kicad/+bug/1847714
2019-10-11 21:01:40 +02:00
Seth Hillbrand d931bc72c7 pcbnew: Snap during routing needs active parent
The router items may not yet have a board item parent.  In this case,
the reference to the parent needs to be guarded before dereferencing.

Fixes: lp:1847717
* https://bugs.launchpad.net/kicad/+bug/1847717

(cherry picked from commit 0f8a1c22ad)
2019-10-11 09:16:58 -07:00
jean-pierre charras 6506f77689 Gencad export: fix an issue in hash_eda calculation,
that can generate the same hash for 2 different footprints.
Therefore, for some footprints, the right footprint was not associated to the component.
The hash calculation was using a XOR to combine 2 sub hash values.
This is not a reliable way to combine these hash values.
They are now added.
Looks better to identify similar and different footprints.

Fixes: lp:1847575
https://bugs.launchpad.net/kicad/+bug/1847575
2019-10-10 20:20:45 +02:00
Seth Hillbrand 0d64b38dbc pcbnew: Remove snapping to hidden items
Items and layers that are hidden in the view should not be used as snap
points.  This happens in multiple locations:
1) Grid Helper for normal tools
2) TOOL_BASE::snapToItem for router

Resolves KiPro Issue #116

Fixes: lp:1833128
* https://bugs.launchpad.net/kicad/+bug/1833128

(cherry picked from commit cecfeea947)
2019-10-10 09:47:34 -07:00
jean-pierre charras 7856061cf0 Fix a few wxWidget asserts related to not existing block operations from mouse drag command.
block rotate and block mirror are not implemented in HandleBlockPlace.
(only available from context menu)

Fixes: lp:1847554
https://bugs.launchpad.net/kicad/+bug/1847554
2019-10-10 10:07:15 +02:00
jean-pierre charras 0210e414d2 Fp editor, DIALOG_FOOTPRINT_FP_EDITOR: fix a very annoying issue: the value field was copuled to the fp name. Unlike schematic symbols, the value field and the footprint name are 2 different fields. So coupling these fields in the DIALOG_FOOTPRINT_FP_EDITOR dialog created serious issues.
Fixes: lp:1846533
https://bugs.launchpad.net/kicad/+bug/1846533
2019-10-09 18:58:23 +02:00
jean-pierre charras 41231e8ae2 Gerber file generation: fix incorrect aperFunction attribute for graphic items on edge cut layer.
Was NonConductor. Must be Profile.
From master branch.
2019-10-09 16:02:45 +02:00
jean-pierre charras ba2e34682e Gerbview: enhancement: show attributes for polygons (Regions in Gerber dialect) that have no DCode
This change is needed to follow current specifications in Gerber X2
2019-10-08 10:25:25 +02:00
jean-pierre charras b234ff9234 Eeschema: fix issues with pin shapes related to clock input pin shapes.
Fixes from master, commit eaea03217:
* Fix not drawn shapes for clock low, inverted clock and broken shape for falling edge clock
* Especially, shape for falling edge clock was a not existing shape, therefore useless.
* now falling edge clock and clock low shape are similar.
2019-10-08 10:11:56 +02:00
Ian McInerney 3442cc3d1a pcbnew: Don't reset router settings when breaking a track
Calling Init() in an action routine will reset the router
settings to the state they were in when first starting pcbnew.
The Init() function is automatically called when the tool is created.

Fixes: lp:1843810
* https://bugs.launchpad.net/kicad/+bug/1843810
2019-10-07 16:10:22 -04:00
Ian McInerney e618e34c94 pcbnew: Clean up extension handling in graphics plugins
* Fix wildcard display in the file selector dialog (on GTK
  it would show the regex to the user)
* Move the file extension comparison into a common function

(cherry picked from commit b33c3a5ad8)
2019-10-04 16:01:15 -04:00
Adam Wolf 105c3b0a4c Add additional ngspice codemodel path for launching from standalone eeschema on macOS.
(cherry picked from commit c7c49cee5a)
2019-10-04 14:33:23 -04:00
Ian McInerney 69d0446019 Update pleditor path for run from build directory
(cherry picked from commit 3a2dbf7786)
2019-10-04 07:58:17 -04:00
jean-pierre charras 078045f73b Gerbview: fix incorrect canvas type saving after closing Gerbview.
Was due to the fact the canvas type was now saved into m_canvasType when opening Gerbview.
2019-10-02 18:30:36 +02:00
jean-pierre charras 78af1daa2e Fix an issue in DIALOG_NETLIST: if the netlist filename does not exist, one cannot always modify the entered name.
(from master branch)
2019-09-30 19:43:25 +02:00
jean-pierre charras 0bd0d57a81 Cairo print, on GTK: use a better DPI definition to avoid artifacts rendering (GTK specific) Previously, a 600 DPI was used to set device scale (can create minor visible rounding issues). Using now 4800 DPI to reduce these rounding artifacts.
Fixes: lp:1845229
https://bugs.launchpad.net/kicad/+bug/1845229
2019-09-27 11:17:58 +02:00
jean-pierre charras 9dd5b6ce37 simulator: plot curves: fix incorrect draw area limits calculation when zooming.
Fixes: lp:1674132
https://bugs.launchpad.net/kicad/+bug/1674132
2019-09-26 16:30:28 +02:00
Seth Hillbrand d862cdaa72 pcbnew: properly close tags when handling bad poly
The parenthesis depth is 2 when the polygon isn't closed.  This
shouldn't happen but we have the fall-through to handle odd cases

Fixes: lp:1844872
* https://bugs.launchpad.net/kicad/+bug/1844872
2019-09-21 09:25:16 -07:00
Seth Hillbrand 4f57de9688 connectivity: Use pad anchor for connections
The pad should use its anchor point rather than the geometrical center
of the pad for connections.
2019-09-19 13:25:26 -07:00
Seth Hillbrand 92b6e05909 connectivity: Check all anchors for connection
With pads, we should check available anchor points for each connection,
increasing probability of finding connection to match fill algorithm

Fixes: lp:1844661
* https://bugs.launchpad.net/kicad/+bug/1844661

(cherry picked from commit b7128639f8)
2019-09-19 12:46:03 -07:00
Ian McInerney 2bd0bae2f7 Remove unneeded wxWidgets version checks in the code
Now that the minimum version is 3.0.0, we don't need to actually
check if the version is greater than 3.0.0 inside the code.

(cherry picked from commit a37d8f2859)
2019-09-18 14:27:30 -04:00
Wayne Stambaugh 69b5d24f28 Eeschema: do not save legacy symbol libraries in schematic file.
Fixes lp:1843473

https://bugs.launchpad.net/kicad/+bug/1843473
(cherry picked from commit 7cf42bb308)
2019-09-18 14:24:20 -04:00
Wayne Stambaugh e5dcb9d9da Eeschema: improve error message when writing cache library.
Remove duplicate missing symbol names from the extended error message.

Fixes lp:1842452

https://bugs.launchpad.net/kicad/+bug/1842452
(cherry picked from commit 18667377f7)
2019-09-13 15:58:37 -04:00
jean-pierre charras 4db8638f7e PANEL_SETUP_NETCLASSES: fix not working (immediately closed) wxChoice widgets to select a filter This happens with wxWidgets 3.0.4 on Windows and is a side effect of a call to Layout(). The fix just calls Layout() only when needed.
Fixes: lp:1843594
https://bugs.launchpad.net/kicad/+bug/1843594
2019-09-13 11:53:03 +02:00
Jeff Young cec885daf9 Partial cherry-pick of f1790c24e5.
Fixes: lp:1842199
* https://bugs.launchpad.net/kicad/+bug/1842199
2019-09-12 22:15:36 +01:00
Michal Jahelka 90fbf27114 c3d_render_ogl_legacy.cpp: initialize m_Emissive member of SMATERIAL to be sure it is set to 0, 0, 0 2019-09-10 17:46:35 +02:00
Jeff Young f1436cec9b Restore PointCloserThan() behaviour to really be "closer than".
Change calls which really want it to be "closer than or equal" to
distance + 1.

Fixes: lp:1843329
* https://bugs.launchpad.net/kicad/+bug/1843329

(cherry picked from commit 25fa2131d2)
2019-09-10 12:57:52 +01:00
Jeff Young cf968cb6b5 Performance enhancement. 2019-09-09 23:22:29 +01:00
Jeff Young 2278f40051 Fix zero failure in SEG::PointCloserThan().
Fixes: lp:1843329
* https://bugs.launchpad.net/kicad/+bug/1843329
2019-09-09 23:22:29 +01:00
Ian McInerney 18a76d3a87 Manually put the UNIT_BINDER text on the primary selection clipboard
The OnKillFocus handler of the UNIT_BINDER replaces the text in the
control with the evaluated string, which removes the selection. To
get the original text on the primary selection clipboard, we must
add it ourselves.

Fixes: lp:1794623
* https://bugs.launchpad.net/kicad/+bug/1794623
2019-09-09 09:02:23 -07:00
Jeff Young 6a65461ec7 Replace buggy code in TestSegmentHit() with call to SEG::PointCloserThan()
Fixes: lp:1843101
* https://bugs.launchpad.net/kicad/+bug/1843101

(cherry picked from commit 6f0d8c3eac)
2019-09-08 12:40:33 +01:00
Jeff Young a5a0a7c4f3 Fix bug with high-frequency plots.
Fixes: lp:1839712
* https://bugs.launchpad.net/kicad/+bug/1839712

(cherry picked from commit 2ac270ce8e)
2019-09-08 01:12:33 +01:00
Jeff Young f1e6f8042c Check for dup layer names in the GUI, not in the internals.
Doing so in the internals keeps users from being able to swap layer
names as the dialog does each layer name change individually.

Fixes: lp:1842665
* https://bugs.launchpad.net/kicad/+bug/1842665

(cherry picked from commit f491b7fff7)
2019-09-07 23:57:49 +01:00
Jeff Young 848873d87e Add some protection against newlines sneaking into the file.
Fixes: lp:1842943
* https://bugs.launchpad.net/kicad/+bug/1842943
2019-09-07 02:32:56 +01:00
Jeff Young 75bb864237 Workaround wxWidgets inability to find the default PDF viewer.
Fixes: lp:1843061
* https://bugs.launchpad.net/kicad/+bug/1843061

(cherry picked from commit d55f4d05b4)
2019-09-07 00:07:06 +01:00
Ian McInerney d5275b16aa eeschema: Find the closest line end to the mouse when grabbing
Fixes: lp:1842175
* https://bugs.launchpad.net/kicad/+bug/1842175
2019-09-06 14:16:56 -07:00
Seth Hillbrand 15d1b6cef0 eeschema: Handle broken spin style value
The spin style is stored as a numeric and can be corrupted.  We handle
this by triggering assertions for debugging the bad value while
resetting to default if we have non-valid spin values that are outside
the array.

Fixes: lp:1843091
* https://bugs.launchpad.net/kicad/+bug/1843091

(cherry picked from commit c3226653cc)
2019-09-06 13:18:34 -07:00
Wayne Stambaugh 6d4dd3e17a Pcbnew: fix size of graphics import warning dialog.
Use the HTML_MESSAGE_BOX window to present the warning messages rather
than wxMessageBox which would overflow the display when there were a lot
of graphic items that could not be parsed.

Fixes lp:1839565

https://bugs.launchpad.net/kicad/+bug/1839565

(cherry picked from commit 24454f5105)
2019-09-06 14:59:40 -04:00
Ian McInerney 649c22a34e wxWidgets compatibility fixes
* Remove unneeded check
* Fix WX_GRID since upstream renamed a variable in 3.1.3

(cherry picked from commit 8d86d94a4d)
2019-09-06 08:48:03 -04:00
Jeff Young 8d04d39036 Cherry-pick of https://git.launchpad.net/kicad/patch/?id=c03535343c67c17ddf0ac18621743d9cf762eb05
Fixes: lp:1842652
* https://bugs.launchpad.net/kicad/+bug/1842652
2019-09-04 20:08:39 +01:00
Jeff Young 0e90c719b0 Update description in footprint tree when it's edited.
Fixes: lp:1842660
* https://bugs.launchpad.net/kicad/+bug/1842660

(cherry picked from commit 6688e80131)
2019-09-04 17:24:17 +01:00
jean-pierre charras a79526cad8 Footprint viewers: force cairo canvas instead of legacy canvas when the legacy canvas is selected in the board editor.
Legacy canvas does not work in footprint preview panel and does not work fine in footprint viewer frame.

Fixes: lp:1842483
https://bugs.launchpad.net/kicad/+bug/1842483
2019-09-04 16:00:54 +02:00
jean-pierre charras d05d8b6100 Pcbnew: Fix incorrect canvas type saved in config, when the type is legacy canvas. 2019-09-04 11:22:55 +02:00
Jeff Young 9856867954 Correct tooltip for Footprint Filter icon on Cvpcb toolbar.
Fixes: lp:1842477
* https://bugs.launchpad.net/kicad/+bug/1842477
2019-09-03 19:46:39 +01:00
Ian McInerney 19064b680e Make the extension check for graphics import case insensitive
The regex for the file extension that matches against all case
possibilities is only built on Linux.

Fixes: lp:1842180
* https://bugs.launchpad.net/kicad/+bug/1842180
2019-09-02 10:03:39 +02:00
jean-pierre charras 95265c765b Pcbnew, DIALOG_TEXT_PROPERTIES: make lines thickness editable when editing a dimension.
From Master branch (commit 762dabd7)

Fixes: lp:1841797
https://bugs.launchpad.net/kicad/+bug/1841797
2019-09-02 10:03:39 +02:00
Jeff Young 1ed8912f57 Workaround an issue where a throw terminates (even when there's a catch for it).
You can trigger it before this fix by running Cvpcb when a .kicad_mod file is
incorrectly set as "Legacy" in your footprint table.

(cherry picked from commit e269b5d1b9)
2019-09-01 12:37:58 +01:00
Jeff Young 82a0eb4413 Use Move() instead of SetPosition() so that the second pt gets updated too.
Fixes: lp:1841989
* https://bugs.launchpad.net/kicad/+bug/1841989

(cherry picked from commit 315a99e0fe)
2019-08-30 23:32:54 +01:00
Jeff Young be7215402b Partial cherry-pick of 79d062aefc. 2019-08-30 13:47:39 +01:00
Seth Hillbrand 4500b064d8 Handle active layer overloading
Setting the active layer should be tied to the events that are triggered
by the layer change and overloaded for each frame.  This ties the hotkey
back to these events.

Note: In the 5.1 cherry-pick this also adds the missing hotkey to
footprint editor

Fixes: lp:1838244
* https://bugs.launchpad.net/kicad/+bug/1838244

(cherry picked from commit 494d0de9b8)
2019-08-28 05:57:48 -07:00
jean-pierre charras 93d191d7c9 fix compil error 2019-08-28 10:05:25 +02:00
jean-pierre charras 1607ceaf3e Eeschema, symbol tree selector: make the selected lib and symbol readable.
Previously, the background was highlighted, but not the text.
On Windows, the text was unreadable, until it was selected.

From Master, commit 34e00bdb.
2019-08-28 09:34:46 +02:00
Jeff Young 5b24ea9dd9 Clearance should be in mils, not inches.
Fixes: lp:1841360
* https://bugs.launchpad.net/kicad/+bug/1841360

(cherry picked from commit 7c85dc6cd7)
2019-08-27 21:15:54 +01:00
Jeff Young c879dcaf7d Sort pins by number when grouping by name.
Fixes: lp:1828648
* https://bugs.launchpad.net/kicad/+bug/1828648

(cherry picked from commit 97212acecb)
2019-08-27 21:15:17 +01:00
Jeff Young 86691dabbf Partial cherry-pick of 03da721030.
Fixes: lp:1841361
* https://bugs.launchpad.net/kicad/+bug/1841361
2019-08-27 18:16:25 +01:00
Seth Hillbrand fe71a66bb9 pcbnew: Force resize event when changing pad type
The local settings panel needs to have its children sized when shown.
Triggering a resize event on changing the pad shape accomplishes this.
This is not triggered in master due to refactor of the custom pad
connection options.

Fixes: lp:1837789
* https://bugs.launchpad.net/kicad/+bug/1837789
2019-08-27 05:55:04 -07:00
Seth Hillbrand 80e0d848f2 eeschema: Modify all units at the same time
When editing symbol library reference, this ensures that all units are
modified by the same action and the component is not represented by its
subunits.

Fixes: lp:1834509
* https://bugs.launchpad.net/kicad/+bug/1834509
2019-08-26 20:42:29 -07:00
Seth Hillbrand 8b3a2984bf pcbnew: Two layer boards need both masks
Adds the missing default layer to the default board setups for two
layers with parts on single side (either top or bottom)

Fixes: lp:1841294
* https://bugs.launchpad.net/kicad/+bug/1841294
2019-08-26 17:14:13 -07:00
Seth Hillbrand fccce265aa pcbnew: Retain 45° constraint
This also finishes the polygon with 45° lines when chosen as a create
option.

Fixes: lp:1833673
* https://bugs.launchpad.net/kicad/+bug/1833673
2019-08-26 14:33:30 -07:00
Seth Hillbrand a43a228f78 eagle: Set module-relative position of ref/val
We need to set the footprint local coordinates of the footprint
reference and value fields at instantiation separately from the
TEXT_DIVERS elements.

Fixes: lp:1829727
* https://bugs.launchpad.net/kicad/+bug/1829727
2019-08-26 09:56:42 -07:00
Jeff Young dd8610fd5c Don't apply GTK fix to OSX as it causes a hang.
Fixes: lp:1841379
* https://bugs.launchpad.net/kicad/+bug/1841379

(cherry picked from commit de8f97be6b)
2019-08-26 00:50:54 +01:00
Seth Hillbrand b991beb712 pcbnew: Fix error in connecitivty calculation
Point in polygon should test against half the stroke width as the stroke
is performed _on_ the polygon edge.

(cherry picked from commit 820c2d2722)
2019-08-23 10:52:11 -07:00
Seth Hillbrand 25f6483488 gerbview: Ensure selection lives on top
Just picking the next layer will be overwritten when we have multiple
objects on the same layer in gerbview.  Move the selection to the top to
ensure it is out top-most layer when drawing.

Fixes: lp:1833868
* https://bugs.launchpad.net/kicad/+bug/1833868

(cherry picked from commit 77488e379c)
2019-08-22 10:52:56 -07:00
Seth Hillbrand efc0325e14 Handle wx scrollbar thumbs in system-independent way
The thumb size changes between system versions and (on GTK) render
managers, so hard-coded wasn't working.  This gets the actual value from
the system and uses to adjust the range.  Changes in the range can also
trigger the refresh.

Fixes: lp:1822617
* https://bugs.launchpad.net/kicad/+bug/1822617

Fixes: lp:1816749
* https://bugs.launchpad.net/kicad/+bug/1816749

(cherry picked from commit 85df994eda)
2019-08-22 10:16:25 -07:00
Seth Hillbrand d19ec021fe PNS: Check that we are optimizing a pad
Vias are also sent to breakout optimizer, so we need to check for the
solid cast before dereference.

Fixes: lp:1841057
* https://bugs.launchpad.net/kicad/+bug/1841057

(cherry picked from commit 03d5bf0df5)
2019-08-22 09:03:12 -07:00
Seth Hillbrand b34a307936 pcbnew: Scale line width for import
The line width in the import dialog is meant to reflect the resulting
width and not the given width of the file.

Fixes: lp:1831496
* https://bugs.launchpad.net/kicad/+bug/1831496

(cherry picked from commit 22fdc7f51f)
2019-08-21 10:35:40 -07:00
Seth Hillbrand fb565caf7b pcbnew: Optimize pad connection revision
This modifies that logic for optimizing pad connections.

1) Custom pads now prefer the connections to their longer side.  This is
particularly important to match the behavior in a rectangular pad
2) Costs for straight lines are non-zero.  This favors fewer connections
3) Custom pad breakouts are at the polygon boundary rather than offset
by 0.1mm.  This also matches the circular and rectangular paradigm.
4) Line Heads contained in the pad itself are not optimized.  This
prevents escaping the pad unnecessarily

Fixes: lp:1824182
* https://bugs.launchpad.net/kicad/+bug/1824182

(cherry picked from commit 06cb21cc47)
2019-08-20 19:37:59 -07:00
Seth Hillbrand 6796e8fff6 EEschema: Plot stroked edges over BG
Items that have BG fill need to be plotted in the background but we
still need their stroked edges to be in the FG.  This is a workaround
that overplots the edges ensuring visual similarity.  Re-working the
plot engine to support layers is a larger project.

Fixes: lp:1833428
* https://bugs.launchpad.net/kicad/+bug/1833428
2019-08-20 12:03:19 -07:00
Seth Hillbrand 213547f545 SVG: Correct plot fills for arcs/polylines
When plotting in Eeschema, various elements may be filled with either
the foreground or background colors.  The fill mode is rather unique,
requiring un-stroked pie wedges for arcs and both closed and open filled
polylines.

Fixes: lp:1840769
* https://bugs.launchpad.net/kicad/+bug/1840769
2019-08-20 12:01:00 -07:00
Jeff Young 73851e962b Implement undo/redo for lock/unlock/toggle lock.
Fixes: lp:1840770
* https://bugs.launchpad.net/kicad/+bug/1840770

(cherry picked from commit b219fbc3d2)
2019-08-20 16:42:20 +01:00
Jeff Young de22204514 Allow mouse drag to initiate a router drag if over a track or via.
Fixes: lp:1840694
* https://bugs.launchpad.net/kicad/+bug/1840694

(cherry picked from commit 1bfefc61ea)
2019-08-19 23:32:56 +01:00
Seth Hillbrand ebba15fe67 Alphabetize Library Table returns
KiCad is case sensitive but we need to be consistent in displaying sort
order as case insensitive (same as file systems)

Fixes: lp:1836911
* https://bugs.launchpad.net/kicad/+bug/1836911
2019-08-19 15:23:29 -07:00
Jeff Young c1cd3339fa Fix assertion in new Duplicate Hotkey warning message. 2019-08-19 14:24:26 +01:00
Jeff Young 713a296a59 Update all aliases of current node after Symbol Properties dialog.
Fixes: lp:1840466
* https://bugs.launchpad.net/kicad/+bug/1840466
2019-08-19 10:55:17 +01:00
jean-pierre charras 06bde527d5 Pcbnew, layer manager: fix flicker when loading a file, and incorrect size on start when no file is loaded
From master, commit b25ffc0
2019-08-19 10:58:45 +02:00
Erik Bosman dcd31f5701 Fix a null-pointer dereference in 5.1 branch
TRACK::GetEndNetCode() can get called using a NULL-pointer as 'this'.
The compiler assumes this won't happen and optimizes away a NULL pointer
check at the start of the function (so we might as well remove this check.)

Fixes: lp:1840562
https://bugs.launchpad.net/kicad/+bug/1840562
2019-08-18 14:59:58 +02:00
Seth Hillbrand 65f2af5849 3d: Disable floor rendering by default
The floor render in raytracing creates interesting shadow effects but
significantly increasing the processing time for renders and has the
side effect of making the bottom of the board very dark if you simply
flip it over.  Making this option off by default, we allow power users
to turn it on if needed for their renders while speeding up the default
raytrace and preventing new user confusion.

(cherry picked from commit 4fcfd266e0)
2019-08-16 11:42:21 -07:00
Seth Hillbrand 2dd7a8637c pcbnew: Handle edge cuts in footprints for bbox
The Board bounding box calculation has two modes: edges only and
everything.  While the everything mode works as expected, the edges only
calculation (and everything that depends on it) was seeing only the edge
cuts on the board drawings layer and not the footprint edge cuts.

Fixes: lp:1839768
* https://bugs.launchpad.net/kicad/+bug/1839768

(cherry picked from commit 99859727e8)
2019-08-16 11:14:14 -07:00
Seth Hillbrand 211d056728 3d-viewer: Remove dead code
The 2d-bbox of the 3d viewer was calculated and set but never used

(cherry picked from commit 59ed9f086f)
2019-08-16 11:01:01 -07:00
Seth Hillbrand dc0aed5b16 Allow EDA_RECT to properly be uninitialized
The base initialization of EDA_RECT sets a 0/0/0/0 rectangle that
prevents merging properly with valid EDA_RECT.  This sets the default to
be uninitialized until the internal data are set.

(cherry picked from commit 46feb76aba)
2019-08-16 11:01:01 -07:00
Simon Schubert 5064df4ba2 kicad2step: scale models
Fixes: lp:1784257
* https://bugs.launchpad.net/kicad/+bug/1784257

(cherry picked from commit a0ed40876d)
2019-08-15 14:32:32 -07:00
Simon Schubert 469c31da97 3d: min dot needs to be square
Given that we compare the dot product (square of length) to s_min_dot,
it means that s_min_dot also needs to be square, or we wind up
converting line segments into circles that are visually distinct from
circles, leading to gaps in polylines.

(cherry picked from commit 0823692dda)
2019-08-15 14:32:32 -07:00
Simon Schubert 5fb41e6ecc 3d canvas: use radius, not width for circles
(cherry picked from commit e01348cccc)
2019-08-15 14:32:32 -07:00
Simon Schubert a68a442bbb SVG plot: output invisible text in addition to plotting
Fixes: lp:1544918
* https://bugs.launchpad.net/kicad/+bug/1544918

(cherry picked from commit 176fe80425)
2019-08-15 14:32:32 -07:00
Seth Hillbrand 84db5644d6 pcbnew: Adjust drag snapping to avoid start
When dragging, you will seldom want to snap to the original item.  This
commit prevents the "size of track" snap to the original item and
replaces it with an auxilary grid origin for the snap.  This means
effectively that the snap will happen to grid for the original item
unless the cursor is closer to the original item line than it is to the
grid crossing.

Fixes: lp:1820248
* https://bugs.launchpad.net/kicad/+bug/1820248

(cherry picked from commit 0de25e557b)
2019-08-15 12:43:19 -07:00
Seth Hillbrand fc1fb7a590 PNS: Don't allow routing on hidden layers
If the layer is not shown, we should not be allowing it's items to be
selected and chosen as the start/end items in the router.
2019-08-15 12:38:16 -07:00
Wayne Stambaugh dc91d4eca8 Symbol editor: fix mnemonic issues in pin properties dialog.
Control ordering is critical to make dialog mnemonics work correct.  The
static text with the mnemonic must immediately proceed the control and
no additional controls can be added between static text/control pair.
Fixing this required adding the units static text controls after all of
the mnemonic static text controls and their associated edit controls.
Mnemonics do not work for read only controls so all of the combobox
controls were moved after the text controls.

Fixes lp:1818930

https://bugs.launchpad.net/kicad/+bug/1818930
(cherry picked from commit 92fe201c5b)
2019-08-15 15:10:43 -04:00
Shawn Anastasio f6a42a36d6 Fix libcontext on PPC64 ELFv2
libcontext currently restores and saves the FPSCR register
on ppc64. This behavior is fine (though unnecessary) on the
ELFv1 ABI which designates the register as volatile, but has
been observed to cause crashes on ELFv2 systems.

The ELFv2 ABI designates the FPSCR register as Limited-access
and specifies specific conditions that must be met to clobber
it. It does not seem that a context swap function meets these
conditions (and indeed, the save/restore register example in the
ABI document does not modify FPSCR).

This patch fixes ELFv2 ABI compliance by removing the FPSCR
save/restore code in libcontext entirely. This fixes observed
crashes on the platform and should have no consequence for
ELFv1 support.

Fixes: lp:1840088
* https://bugs.launchpad.net/kicad/+bug/1840088

(cherry picked from commit 3e22b75948)
2019-08-14 11:18:25 -07:00
Wayne Stambaugh 2a769dc0b0 Eeschema: fix bug in sheet name comparisons on Windows.
The use of wxPATH_UNIX when calling GetFullPath() on windows drops the
volume identifier (c:\) from the file name which will cause comparison
failures.

(cherry picked from commit 0328f3e33b)
2019-08-13 16:36:01 -04:00
Jeff Young 3475bfb2aa New move tool doesn't require GetAndPlace to jump through hoops.
And at least one of those hoops leaves the cursor forced.

Fixes: lp:1839877
* https://bugs.launchpad.net/kicad/+bug/1839877

(cherry picked from commit dd938b02df)
2019-08-13 10:02:57 +01:00
jean-pierre charras f9f8fade89 Pcbnew plot: fix missing footprint texts on solder mask layers.
Fix from master branch commit 1c295d46a9
2019-08-13 09:55:11 +02:00
Jeff Young e404fb772b Invoke move by ACTION; the EDIT_TOOL does lots of other stuff too.
Fixes: lp:1839877
* https://bugs.launchpad.net/kicad/+bug/1839877

(cherry picked from commit f3f0a6899f)
2019-08-12 23:00:55 +01:00
Wayne Stambaugh 2a9412042c Eeschema: remove dead code from LIB_PART object.
(cherry picked from commit 9020a3a26c)
2019-08-12 12:55:21 -04:00
Wayne Stambaugh e8ab661504 PCB calculator: fix regulator dialog layout.
Set default dialog size to -1,-1 to allow the dialog to size itself
properly to prevent the buttons in the standard dialog button sizer
from being truncated.

Fixes lp:1839695

https://bugs.launchpad.net/kicad/+bug/1839695
(cherry picked from commit e3e546f7d2)
2019-08-12 10:02:15 -04:00
Jeff Young 3f91db25d4 Minimal cherry-pick of c836cc9cf8.
Fixes: lp:1839534
* https://bugs.launchpad.net/kicad/+bug/1839534
2019-08-10 22:27:05 +01:00
Wayne Stambaugh 300381ba4d KiCad: fix new project from template bug.
Do no rename symbol library files to the new project name.  Only rename
the cache library.  This prevents breaking symbol library links in the
schematic due to the project symbol library table pointing to the wrong
library file name.

Fixes lp:1837667

https://bugs.launchpad.net/kicad/+bug/1837667
(cherry picked from commit c7fc54b348)
2019-08-07 15:39:19 -04:00
Seth Hillbrand 4363e6a213 eeschema: Fix list invalidation
When removing a junction, we need to keep the next pointer for deleted
item, marking them with a flag until committed.

Fixes: lp:1837398
* https://bugs.launchpad.net/kicad/+bug/1837398
2019-08-05 09:03:38 -07:00
Wayne Stambaugh 450dac4b1e Revert "Revert "Eeschema: remove rogue symbol libraries from project file.""
This reverts commit 0893e0043f.
2019-08-04 13:05:47 -04:00
Wayne Stambaugh 278127fe29 Revert "Revert "Eeschema: fix edit sheet bug.""
This reverts commit 2d48c81d58.
2019-08-04 13:05:35 -04:00
Wayne Stambaugh 23d71de75f Revert "Revert "Eeschema: fix many append schematic bugs.""
This reverts commit 238fb00727.
2019-08-04 13:05:09 -04:00
Wayne Stambaugh d86789898d Begin version 5.1.5 development. 2019-08-04 12:38:05 -04:00
Wayne Stambaugh c3dc1f65d4 Tag release version 5.1.4. 2019-08-04 12:36:25 -04:00
Wayne Stambaugh 238fb00727 Revert "Eeschema: fix many append schematic bugs."
This reverts commit 3518153d5b.
2019-08-04 12:34:25 -04:00
Wayne Stambaugh 2d48c81d58 Revert "Eeschema: fix edit sheet bug."
This reverts commit 6051dfae30.
2019-08-04 12:33:55 -04:00
Wayne Stambaugh 0893e0043f Revert "Eeschema: remove rogue symbol libraries from project file."
This reverts commit 5d60fe6812.
2019-08-04 12:33:19 -04:00
Jeff Young 72c0267fe6 Ativate delete tool so it can display the selection clarification menu when needed.
Fixes: lp:1835371
* https://bugs.launchpad.net/kicad/+bug/1835371

(cherry picked from commit c60118b6a4)
2019-08-03 22:49:27 -06:00
Seth Hillbrand c9956def36 pcbnew: Fix copy-paste error from 161dc9ce7
create_vrml_shell() needed the idxSide check but create_vrml_plane only
had an extra variable that wasn't used and so shouldn't be checked.
2019-08-02 13:14:02 -07:00
Wayne Stambaugh 5d60fe6812 Eeschema: remove rogue symbol libraries from project file.
Check for symbol libraries that somehow ended up in the project file
after remapping occurred and remove all of them to prevent potentially
broken symbol library links.

Add nagware dialog to warn the user and a checkbox to never show the
dialog again.

Fixes lp:1838185

https://bugs.launchpad.net/kicad/+bug/1838185
(cherry picked from commit 8789ab9265)
2019-08-01 15:24:55 -04:00
Wayne Stambaugh 6051dfae30 Eeschema: fix edit sheet bug.
Remove an existing sheet from the current page that requires a schematic
load from file to prevent a corrupt screen list from causing a segfault.

Merge the edit sheet file loading with the append schematic code since
they are functionally the same.  This allows the sheet edit code to
take advantage of all of the added broken symbol library links added in
the recent append schematic fixes.

Fixes lp:1835841

https://bugs.launchpad.net/kicad/+bug/1835841
(cherry picked from commit b595dc0d3b)
2019-08-01 15:24:55 -04:00
Wayne Stambaugh 3518153d5b Eeschema: fix many append schematic bugs.
Do not add cache library from another project to old library list.  This
is wrong and can cause all kinds of symbol library linking issues.  It's
better to force the user to fix broken symbol library links than the false
security of using multiple cache libraries.

Use correct paths when appending schematic outside of the current project
path when hierarchical sheets are appended.  If the path can be relative,
give the user the option to use either relative or absolute paths.

Do not change symbol library names in schematics appended from a source
outside the current project.  This will almost ensure the symbol library
links will be broken in the source project.

When the appended schematic is from another project, attempt to check all
of the possible combinations of symbol library table importing that could
cause broken symbol library links and give the user the option of canceling
the append operation or live with the possibility that there may be broken
symbol library links.

When the append schematic is in the current project path but not part of
the schematic, check to see if there are any library nicknames that do
no exist in the project symbol library table and give the user a chance
to cancel the append process.

(cherry picked from commit 9fae30162d)
2019-08-01 15:24:55 -04:00
Seth Hillbrand cf949609b2 eeschema: Properly map edge cases of legacy onto GAL
While we do not generate these arcs internally, some external tools
generate arcs that are technically valid but display correctly only
because of an oddity in the degeneracy mapping.

Fixes: lp:1838557
* https://bugs.launchpad.net/kicad/+bug/1838557
2019-08-01 11:45:10 -07:00
Jeff Young d482a8805c Perform better cleanup after cancelling text placement.
Fixes: lp:1838452
* https://bugs.launchpad.net/kicad/+bug/1838452
2019-07-31 23:17:08 -06:00
Seth Hillbrand 161dc9ce7e pcbnew: Fix VRML export checking
In rare cases, the VRML triangulator may claim to work but return empty
vectors.  These cases need to be caught before we dereference the vector
elements.

Fixes: lp:1838448
* https://bugs.launchpad.net/kicad/+bug/1838448
2019-07-31 20:03:49 -07:00
jean-pierre charras 090073cc3b Pcbnew, exchange footprints: fix a bug that prevent the new footprint to be at the right place.
Fixes: lp:1838446
https://bugs.launchpad.net/kicad/+bug/1838446
2019-07-31 12:07:49 +02:00
Ian McInerney 6ae718e4d6 pcbnew: Fix DXF units in drill map plotting
Fixes: lp:1836924
* https://bugs.launchpad.net/kicad/+bug/1836924

(cherry picked from commit 6c401ecce7)
2019-07-30 17:20:38 -04:00
Thomas Pointhuber 783b1cb611 Fix handling of filled circle in eagle importer (was only partly fixed)
Partly fixed in 4fc692f04b, but missed
that there is a loadPlain where I need to handle this case as well.

(cherry picked from commit 5f438b7a85)
2019-07-30 15:33:39 -04:00
Jeff Young 4b01f80e8d Fix typo in cherry-pick.
Fixes: lp:1838006
* https://bugs.launchpad.net/kicad/+bug/1838006
2019-07-30 11:49:06 -06:00
Jeff Young c8278f377b Alternative to cherry-picking b70df18939.
Fixes: lp:1838158
* https://bugs.launchpad.net/kicad/+bug/1838158
2019-07-29 20:19:46 -06:00
jean-pierre charras d34b664933 Simulation: do not add .save V(0) and/or .save V(GND) to ngspice.
These 2 nets are internally added by ngspice (info from Holger Vogt)

(cherry picked from commit d92396341e)
2019-07-28 04:52:57 -07:00
jean-pierre charras c8f40e1d26 PANEL_SETUP_NETCLASSES_BASE: fix minor wxAlert. 2019-07-28 13:26:58 +02:00
jean-pierre charras 185a8d7582 Try to fix UI issues in select layer pair dialog and slect layer dialog.
Fixes: lp:1838173
https://bugs.launchpad.net/kicad/+bug/1838173
2019-07-28 12:55:47 +02:00
jean-pierre charras 8373e91a1b Python scripting: fix missing definition of uint32_t (and some other similar defs).
Fixes: lp:1837867
https://bugs.launchpad.net/kicad/+bug/1837867
2019-07-27 08:22:10 +02:00
Jeff Young 6aeedfb70c Partial cherry-pick of 3904d7ccfc.
Fixes: lp:1838006
* https://bugs.launchpad.net/kicad/+bug/1838006
2019-07-26 20:46:12 -06:00
Stefan Hamminga e7f3851212 Rebased LTO fix for coroutines
Fixes: lp:1793329
* https://bugs.launchpad.net/kicad/+bug/1793329

(cherry picked from commit e58d9606dd)
2019-07-25 12:17:11 -07:00
jean-pierre charras 7df05ade4c Pcbnew: Fix bug in MODULE::FindPadByName( const wxString& aPadName ). This method was using a case insensitive comparison to find the pad matching aPadName. But in netlist we are using case sensitive comparisons to attribute a net to a pad. So if in the netlist there is a pad name that does not match any footprint pad name using case sensitive comparison but if it matches some pads using case insensitive comparison, the net is not set, but the test to detect non existing pads fails. 2019-07-25 17:57:38 +02:00
Seth Hillbrand 24b032ce5b Project Templates: Allow multiple line titles
This fixes two display issues in the project template selector.  The
first captured HTML tags in the template title display and the second
prevented more than one line for showing (at least on GTK) in the
preview.  This prevented disambiguation between the various templates.
2019-07-23 15:05:25 -07:00
Seth Hillbrand b6fe4ff637 eeschema: Clean up backup name
This fixes the last suffix that was missed by 168fa09f5.  The schematic
backup files should have the suffix .sch-bak to distinguish from
.kicad_pcb-bak or other backups.
2019-07-23 10:47:15 -07:00
Wayne Stambaugh 8f1aa28b37 Begin version 5.1.4 development. 2019-07-23 08:16:06 -04:00
Wayne Stambaugh 55c1e22a67 Tag release version 5.1.3. 2019-07-23 08:07:28 -04:00
Jeff Young ca0d4511a9 Copy ratsnest flags when exchanging modules.
Fixes: lp:1834214
* https://bugs.launchpad.net/kicad/+bug/1834214

(cherry picked from commit 2ca379b281)
2019-07-21 20:27:12 -06:00
Jeff Young b56855c542 Don't shove stitching vias.
Whether or not it's a good idea, the current algorithm doesn't support
it and leaves them on top of each other.

Fixes: lp:1833214
* https://bugs.launchpad.net/kicad/+bug/1833214

(cherry picked from commit aa4d7682ca)
2019-07-21 16:41:56 -06:00
Jeff Young 72e8eb3b94 Initialize plot with aux origin checkbox.
Fixes: lp:1836923
* https://bugs.launchpad.net/kicad/+bug/1836923

(cherry picked from commit b5e01ea163)
2019-07-20 07:58:43 -06:00
Jeff Young 281a1cdc2c Update DXF units drop-down.
Fixes: lp:1836927
* https://bugs.launchpad.net/kicad/+bug/1836927

(cherry picked from commit 4a1edf581e)
2019-07-20 07:58:38 -06:00
jean-pierre charras 3c8f901a1f Revert "Fix ngspice netlisting when net names contain '/'"
This reverts commit 216573bf48,
because the issue with net names containing '/' is not actually inside the netlist.
This commit 2165 creates issues with ngspice 2.8 and older, and do not fix anything in ngspice
2019-07-19 15:52:18 +02:00
Seth Hillbrand e0589d2908 pcbnew: Make clearance translucent
This sets the clearance outline to a slightly better opacity to allow
viewing of items behind the routed track clearance.  Future work should
include making this a configuration option.

Fixes: lp:1826719
* https://bugs.launchpad.net/kicad/+bug/1826719
2019-07-18 10:44:44 -07:00
Jeff Young dfd53976d4 Fix double-highlighted radio buttons on GTK.
Fixes: lp:1836538
* https://bugs.launchpad.net/kicad/+bug/1836538
2019-07-17 12:57:21 +01:00
Ian McInerney 02d43be93c pcbnew: Make the netlist class panel usable with a lot of classes
Fixes: lp:1826154
* https://bugs.launchpad.net/kicad/+bug/1826154

(cherry picked from commit 39954b20fe)
2019-07-15 06:12:13 -07:00
jean-pierre charras 2e8bceb676 Fix a minor wxWidgets alert, already fixed in master branch. 2019-07-15 12:27:54 +02:00
Jeff Young 16f9e697ab Allow edits to self-intersecting polygons.
1) Intermediate states might be self-intersecting, and we shouldn't
be policing our users on what order to do things in
2) The polygon might already be self-intersecting, at which point we're
preventing the user from fixing it.

Also includes better const management for SHAPE_POLY_SET API.

Fixes: lp:1833831
* https://bugs.launchpad.net/kicad/+bug/1833831

(cherry picked from commit a3c74051c2)
2019-07-14 18:36:47 +01:00
jean-pierre charras 269f88ee28 Fix incorrect handling of unicode chars (non ASCII7) in filenames in .gbrjob files. 2019-07-14 11:19:03 +02:00
Jeff Young f11d950448 Don't let visibility bit get nuked when updating effects.
Fixes: lp:1836183
* https://bugs.launchpad.net/kicad/+bug/1836183

(cherry picked from commit 6c9e34e799)
2019-07-11 23:01:54 +01:00
Jeff Young 6ba2c44e88 Add FootprintExists() which can be more careful about FS differences.
(And in particular, MSW's case-insensitive FS.)

Fixes: lp:1835999
* https://bugs.launchpad.net/kicad/+bug/1835999

(cherry picked from commit 20036f8105)
2019-07-11 23:01:25 +01:00
Jeff Young d1ed4665de OSX compiler didn't like the other syntax.
(cherry picked from commit f14e41133b)
2019-07-11 12:35:11 -07:00
Seth Hillbrand 5b68cfa018 Fix import graphics routines and tests
The returns of KiCad file extensions on GTK contain basic regex matching
case-insensitive file extensions.  We need to match these in the
provider and tests

(cherry picked from commit 1956c074ba)
2019-07-10 10:47:13 -07:00
Seth Hillbrand 85f88b6b05 Fix case-sensitive import using KiCad std
Fixes: lp:1832853
* https://bugs.launchpad.net/kicad/+bug/1832853

(cherry picked from commit 79e2000af4)
2019-07-10 10:33:03 -07:00
Seth Hillbrand ea467441d2 import_gfx: Make file selection case-insensitive
This adds the upper-case version of files names to the selection box for
filesystems that support case-sensitive file names.

Fixes: lp:1832853
* https://bugs.launchpad.net/kicad/+bug/1832853

(cherry picked from commit 36f70704eb)
2019-07-10 10:32:48 -07:00
Ian McInerney 40ba502853 pcbnew: Clean up warnings with unit handling in the DXF export
(cherry picked from commit ff9d899ae0)
2019-07-10 12:42:54 -04:00
Ian McInerney 09d7d0f1bc Update ngspice build tool script to ngspice-30
(cherry picked from commit 6186dd5c51)
2019-07-10 09:20:41 -04:00
Jeff Young 3418d53a6d Update symbol ID before running Update Fields from Library.
Fixes: lp:1827707
* https://bugs.launchpad.net/kicad/+bug/1827707

(cherry picked from commit fb881ee209)
2019-07-08 22:57:15 +01:00
Ian McInerney d5440d60ab eeschema: Fix initial selected text in reference value dialog
Fixes: lp:1834741
* https://bugs.launchpad.net/kicad/+bug/1834741

(cherry picked from commit e32306c232)
2019-07-08 14:50:53 -04:00
Jeff Young 2ba237ec12 Test for crash bug fix. 2019-07-08 15:34:01 +01:00
Jeff Young 01a343f28e Fix crash when re-entering a drag operation with a move.
Fixes: lp:1834111
* https://bugs.launchpad.net/kicad/+bug/1834111
2019-07-05 02:24:15 +01:00
Jeff Young 85220591e2 Fix bugs in keyboard cursor movement.
1) Generate refreshPreview events so the modern toolset doesn't
fall behind by one event (see LP:1818667)
2) In the legacy toolset don't call unimplemented routines and don't
snap to grid on the non-movement axis.
2019-07-05 01:32:15 +01:00
Jeff Young ecadc8bbba Fix bugs in new wire/line-width split.
If Symbol Editor isn't open then Eeschema needs to read in the
default line width.

Symbol Editor was failing to write line width parameter back to
properties.

Fixes: lp:1835051
* https://bugs.launchpad.net/kicad/+bug/1835051

(cherry picked from commit ef03afe289)
2019-07-03 14:34:11 +01:00
Jeff Young 26c92eaf0f Give up on KillFocus validation.
wxWidgets sends the KillFocus event before the Cancel button event,
and it sets the receiving-focus window pointer to NULL (so you can't
even check for it being the Cancel button.  Last time around (with
the UNIT_BINDER) I also tried a bunch of hacks for whether the window
pointer is NULL, etc., but they aren't discriminatory either.

Fixes: lp:1834975
* https://bugs.launchpad.net/kicad/+bug/1834975

Fixes: lp:1834966
* https://bugs.launchpad.net/kicad/+bug/1834966

(cherry picked from commit 1c30f3d9a9)
2019-07-02 18:13:27 +01:00
jean-pierre charras d129abb9c9 Eeschema, lib editor: fix a message error when loading a symbol from the schematic editor.
Adaptation from master branch, commit ff995bb7
2019-07-02 18:40:48 +02:00
Jeff Young 3b98b00d6f Only warn once in KillFocus for each error value in footprint name.
More than that just gets annoying, and there is at least one edge case
which throws us into an infinite loop if we don't have something to
break us out.

Fixes: lp:1834966
* https://bugs.launchpad.net/kicad/+bug/1834966

(cherry picked from commit 29db6152b3)
2019-07-02 00:48:57 +01:00
Jeff Young ce329e13fb Set library selection when pre-loading the Footprint Viewer.
Fixes: lp:1826932
* https://bugs.launchpad.net/kicad/+bug/1826932

(cherry picked from commit 8efe8d1835)
2019-07-01 22:17:57 +01:00
Seth Hillbrand be9cd98cb1 Move zone refill to action
This unifies the zone refill across architecture into the tool-based
architecture.  Also provides ZONE_FILLER-based progress managment for
tools.
2019-07-01 09:16:32 -07:00
Jeff Young 216acd98d6 Separate default line and wire thicknesses.
Fixes: lp:1834324
* https://bugs.launchpad.net/kicad/+bug/1834324
2019-06-30 11:13:17 +01:00
Jeff Young 10fd8a59b2 Apply relevant fixes from 51479c2042.
Fixes: lp:1834703
* https://bugs.launchpad.net/kicad/+bug/1834703
2019-06-29 21:17:22 +01:00
Seth Hillbrand 3974c6fd89 Enforcing rational limits on length tuner
The length tuning dialog needed validators on close to prevent negative
and percentages >100%

Fixes: lp:1834734
* https://bugs.launchpad.net/kicad/+bug/1834734
2019-06-29 09:37:47 -07:00
Ian McInerney f82962e42c eeschema: Fix python BOM generators to handle symbols
* Implement proper natural sorting of the reference values
* Perform quoting of all items in BOM generators that use csv.writer

Fixes: lp:1833822
* https://bugs.launchpad.net/kicad/+bug/1833822
2019-06-29 17:17:20 +02:00
Seth Hillbrand bf1ced4184 Allow more segments for large-arc footprints
When approximating arcs for polygons, we should allow for large radius
arcs/circles without coarsening the arc beyond a limit.  This is a
5.1.x-only patch to address this issue.  It should not be picked to
master as this is already addressed separately by max_error
2019-06-28 19:25:42 -07:00
Seth Hillbrand cabfcbc73c pcbnew: Drop tracks not on copper
We do not allow non-copper routed tracks and they will break assumptions
elsewhere in the code.  We drop them in the beginning so that they are
not saved.
2019-06-28 19:25:28 -07:00
Wayne Stambaugh 574473c480 Pcbnew: fix clean up tracks and vias segfault bug.
If a track has no connected items, do not attempt to access an empty
connected item map.

Fixes lp:1823973

https://bugs.launchpad.net/kicad/+bug/1823973
2019-06-28 13:12:23 -04:00
jean-pierre charras 17143fd53f Pcbnew, connectivity: fix incorrect detection of dangling track ends when a end is inside a zone.
This end was not detected as connected by the IsDangling method
2019-06-28 15:27:01 +02:00
Jeff Young b8fff99e68 Hook up zone-connection controls in Edit Footprint dialog.
Fixes: lp:1834629
* https://bugs.launchpad.net/kicad/+bug/1834629
2019-06-28 12:26:28 +01:00
Ian McInerney 3b038feae0 Cleanup cmake python dependency handling to catch errors
* Changed the KICAD_SCRIPTING flag to be a global disable, so it
  will disable all other scripting flags when set to OFF
* Added version testing with the wxPython flags to ensure the
  proper version is found for the flags provided

(cherry picked from commit 42e14b5a4e)
2019-06-27 13:41:55 -04:00
jean-pierre charras 032bda223e Gerber drill file: Modify a aperture attribute for oblong holes (slots).
Oblong holes (slots) use now a aperture attribute similar to round holes.
(The previous attribute "slot" is now deprecated)
However they have a specific aperture, and a comment is added in drill files for these apertures.
2019-06-26 17:53:09 +02:00
Jeff Young b16d4d18e0 Don't select items on inactive layers in high-contrast mode.
Fixes: lp:1833870
* https://bugs.launchpad.net/kicad/+bug/1833870
2019-06-26 01:18:59 +01:00
Wayne Stambaugh df3a57dcda Symbol and footprint library table editor fix.
Prevent the symbol and footprint library table editors from substituting
the current project path (${KIPRJMOD}) when adding libraries to the global
library table.  This will almost assuredly fail when opening a different
project.  We still allow users to manually use ${KIPRJMOD} in global table
paths under the assumption that if they are typing this in then they most
likely understand environment variable substitution.

Fixes lp:1830694

https://bugs.launchpad.net/kicad/+bug/1830694

(cherry picked from commit 288982b15d)
2019-06-25 08:46:27 -04:00
Tomasz Włostowski 3bf7ab910f TestSegmentHit: add corner case for null segment (start == end)
Fixes: lp:1833059
* https://bugs.launchpad.net/kicad/+bug/1833059

(cherry picked from commit 6180687bbd)
2019-06-25 08:45:27 -04:00
Seth Hillbrand e8ce0ba6ef pcbnew: Avoid wxassert in message
wxstring::Printf() needs size_t cast to acceptable type or it gives an
assertion in debug mode.
2019-06-24 09:42:06 -07:00
Wayne Stambaugh d8fff5c820 Footprint library nickname comparison fixes.
Footprint library nicknames are case sensitive but the comparison for
the library tree control was case insensitive.

Also make the footprint name comparisons case sensitive as well.  While
not strictly necessary, the plan is to start using the name defined in
the footprint file instead of the file name which will allow for case
sensitivity.

Fixes lp:1833701

https://bugs.launchpad.net/kicad/+bug/1833701
2019-06-24 08:00:21 -04:00
Seth Hillbrand aa9897d932 Fix bug in tesselation
When we hit a self-intersection, we need to be careful that we don't
lose the stop vertex.

Fixes: lp:1833819
* https://bugs.launchpad.net/kicad/+bug/1833819

(cherry picked from commit 6d60b98dc8)
2019-06-23 20:56:29 -07:00
Seth Hillbrand f265a52c96 Enforce build order with qa system
The QA objects link to the direct kiface objects, which creates a second
dependency on the generated lexer files.  To ensure that the primary
apps are finished building them in a (potentially) different thread, we
set a false dependency on the final build product in the qa CMake.

Fixes: lp:1833851
* https://bugs.launchpad.net/kicad/+bug/1833851

(cherry picked from commit 172542cfc4)
2019-06-23 12:53:19 -07:00
Jeff Young f214cfae12 Don't try to show sub-dialog in OnActivate(). High Sierra asserts.
Fixes: lp:1832635
* https://bugs.launchpad.net/kicad/+bug/1832635
2019-06-23 15:39:05 +01:00
Seth Hillbrand febc8cd6aa pcbnew: Ensure save dialog with zones
Fixes: lp:1833748
* https://bugs.launchpad.net/kicad/+bug/1833748
2019-06-22 08:45:00 -07:00
Seth Hillbrand 463e061740 Clear non-copper edge rounding
Non-copper zones do not have a fillet/chamfer option, so we need to
clear it before the zone tool uses the last-used option.

Fixes: lp:1833672
* https://bugs.launchpad.net/kicad/+bug/1833672
2019-06-22 08:25:38 -07:00
Ian McInerney d80759efb8 cvpcb: Implement delete/cut/copy/paste for individual associations
Fixes: lp:1794883
* https://bugs.launchpad.net/kicad/+bug/1794883
2019-06-21 09:58:53 -04:00
Ian McInerney 1d66aad4df cvpcb: Allow the escape key to close the window
Fixes: lp:1830483
* https://bugs.launchpad.net/kicad/+bug/1830483
2019-06-21 09:22:51 -04:00
Seth Hillbrand f5284ced54 Allow null path in 3d model
This allows a setting where the path is not one of the options.  This
permits the user to select once to go to any path option (rather than
off the current and then back to currect) when the filetree doesn't
match the dropdown.  This also selects the drop down item if it matches
the tree.
2019-06-20 20:10:25 -07:00
Ian McInerney c951ca6f47 cvpcb: Added library location to status bar
Fixes: lp:1782805
* https://bugs.launchpad.net/kicad/+bug/1782805
2019-06-20 16:20:15 -04:00
Seth Hillbrand f25ae373bb Fixup previous move commit
The previous commit missed a case where the number was so large that it
overflowed the integer invalidating the comparison.  This protects
against that case by using floating point comparison.
2019-06-20 06:46:41 -07:00
Seth Hillbrand 845833e8fd pcbnew: Enforce maximum movement in Move Exact
This checks the movement against a maximum value that would place the
selection outside of the valid area for the footprint or board.

Fixes: lp:1833478
* https://bugs.launchpad.net/kicad/+bug/1833478
2019-06-20 06:29:53 -07:00
jean-pierre charras f0ac61a8fd Eeschema: minor fix for root sheet plot file name.
Fixes: lp:1833487
https://bugs.launchpad.net/kicad/+bug/1833487
2019-06-20 13:41:04 +02:00
Seth Hillbrand 8f7278e34f Eeschema: Normalize layer ordering between plot and screen
Fixes: lp:1833428
* https://bugs.launchpad.net/kicad/+bug/1833428
2019-06-19 10:49:28 -07:00
Seth Hillbrand b124599de3 Don't skip handled events in GTK
Now that our tool framework handles the hotkeys, we need to skip the
passed handling work-around for actions that are already handled in the
event.

Fixes: lp:1832604
* https://bugs.launchpad.net/kicad/+bug/1832604

(cherry picked from commit b876309999)

Fixes: lp:1819210
* https://bugs.launchpad.net/kicad/+bug/1819210
2019-06-18 22:06:10 -07:00
Seth Hillbrand 697234dd51 eeschema: Insert junctions when repeating
Fixes: lp:1832253
* https://bugs.launchpad.net/kicad/+bug/1832253
2019-06-18 19:38:13 -07:00
Seth Hillbrand ba97494d6f Update toolbar to get new icon/tooltip
After a save-as the footprint belongs to the library, we need to refresh
the toolbar to get the correct icon.

Fixes: lp:1826889
* https://bugs.launchpad.net/kicad/+bug/1826889
2019-06-18 19:24:47 -07:00
Jeff Young 1996fba8a6 Check for a tree selection before checking it against the board item.
Fixes: lp:1833295
* https://bugs.launchpad.net/kicad/+bug/1833295
2019-06-19 00:11:23 +01:00
Wayne Stambaugh a6bbe907ee Set about dialog name for 3D viewer frame.
(cherry picked from commit 2f2c358aef)
2019-06-18 15:32:09 -04:00
Wayne Stambaugh 43579f4c02 Minor library identifier validator change.
Use the wxTextValidator style flag to allow the user to clear the library
identifier string.  Use wxTextValidator::SetStyle( wxFILTER_EMPTY ) to
prevent empty library identifier strings which is the current behavior.

(cherry picked from commit 9f9e87f11f)
2019-06-18 12:16:51 -04:00
Seth Hillbrand 909a25c147 pcbnew: Correct polygon flipping in custom pads
Custom pads are referenced to the anchor pad 0-point, so flipping the
polygon should be about 0 and not the flip point.

Fixes: lp:1831311
* https://bugs.launchpad.net/kicad/+bug/1831311
2019-06-17 15:26:56 -07:00
Wayne Stambaugh aa3aafc4ff Eeschema: fix sheet plotting bug.
Prefix the sheet name with "Sheet: " and the sheet file name with "File: "
when plotting so that it matches the display sheet rendering.

Improve the root sheet plot file name.

Fixes lp:1832081

https://bugs.launchpad.net/kicad/+bug/1832081
(cherry picked from commit 7235da0979)
2019-06-17 17:02:21 -04:00
Seth Hillbrand b32439a694 Plotting: Handle mask transparency
This handles images with transparent colors by mapping the transparent
color to white.  This only works when plotted into the background.
2019-06-17 13:27:58 -07:00
Seth Hillbrand ddbc25077c Eeschema: Plot in same order as drawing
This ensures the junctions are on top and the bitmaps are on bottom
2019-06-17 13:27:11 -07:00
Seth Hillbrand b075886b19 DC printing: Place worksheet behind schematic
And place bitmaps behind other items.  This ensures they are drawn in
the background of the page rather than covering schematic elements.

This also hacks around the buggy wxPostScriptDC implementation that
resets the page to print an image.

Fixes: lp:1819934
* https://bugs.launchpad.net/kicad/+bug/1819934
2019-06-17 13:03:00 -07:00
Wayne Stambaugh eae999a85a Eeschema: allow empty field strings in field table editor.
The grid apply code was always preventing empty fields.  Change this the
broken behavior to allow any field to be empty except the reference and
value fields.

Fixes lp:1832722

https://bugs.launchpad.net/kicad/+bug/1832722
(cherry picked from commit d74ec1a1b2)
2019-06-17 15:06:27 -04:00
Seth Hillbrand 77f0799750 Print bitmaps using BW setting
When selecting the "Print in B&W", all items on the schematic should be
printed using black and white.  This converts the embedded images
greyscale before outputting to the printer
2019-06-17 09:54:52 -07:00
jean-pierre charras 8de93ad8b4 Eeschema: fix incorrect size of junctions on screen.
Fixes: lp:1831931
https://bugs.launchpad.net/kicad/+bug/1831931
2019-06-17 18:08:44 +02:00
Ian McInerney b377b5bbed pcbnew: Fix invalid hotkeys 2019-06-17 08:11:01 -04:00
Seth Hillbrand 75b5324762 Eeschema: Allow junction dots to be hidden
Drawing junction dots at the line width allows users who do not like
them in their schematics to avoid having them drawn.
2019-06-17 04:48:10 -07:00
Wayne Stambaugh 610d200e8a Fix spelling error in symbol library table warning string.
(cherry picked from commit be8fe3884f)
2019-06-16 12:28:56 -04:00
Wayne Stambaugh 8002692f3e CvPcb: fix save changes dialog layout issue.
DIALOG_EXIT was not being laid out correctly after setting the dialog
message.  Rather than fix our custom DIALOG_EXIT, wxMessageDialog and
wxRichMessageDialog were substituted as direct replacements for all
of the variants of DIALOG_EXIT.  This make message dialogs appear more
consistent because wxMessageDialog uses the default platform message
dialog and wxRichMessageDialog uses the default platform rich message
dialog on windows.

Remove DIALOG_EXIT_BASE as it is no longer required.

Fixes lp:1832899

https://bugs.launchpad.net/kicad/+bug/1832899

(cherry picked from commit 3f665318f4ab5c02b7d3c29b5233a273fdac2e4e)
2019-06-16 12:28:35 -04:00
Seth Hillbrand 9496b57b01 tool_mgr: Don't invalidate our own iterators
Re-arranging the stack will invalidate the iterator that is removed and
inserted (begin()).  Because this is not a threaded operation, we can
only do it to ourselves, so check that the operation isn't a NOP before
performing.

Fixes: lp:1832930
* https://bugs.launchpad.net/kicad/+bug/1832930

(cherry picked from commit 552815d486)
2019-06-15 17:49:52 -07:00
jean-pierre charras a5cd5844ec Fix invalid wxImageList build.
Fixes: lp:1832905
https://bugs.launchpad.net/kicad/+bug/1832905
2019-06-15 16:08:07 +02:00
Ian McInerney da16b479a0 Make DXF monochrome output only contain Black layer
Fixes: lp:1832359
* https://bugs.launchpad.net/kicad/+bug/1832359

(cherry picked from commit dc56678289)
2019-06-13 16:10:17 -07:00
Ian McInerney 44f1059000 Allow DXF to be exported in either inches or millimeters
Fixes: lp:1832188
* https://bugs.launchpad.net/kicad/+bug/1832188

(cherry picked from commit d5f680ecd2)
2019-06-13 16:10:12 -07:00
Ian McInerney cf4b41f7d9 pcbnew: Update plot dialog to contain a unit selector for DXF
(cherry picked from commit b2c848579a)
2019-06-13 16:10:03 -07:00
Seth Hillbrand a84ca5b147 cmake: Further petting dependencies
eeschema cpp files consume generated header files that have targets in
the common directory, so no dependencies get created from eeschema.  We
add the dependencies in common to force the setting through libraries.

Fixes: lp:1831643
* https://bugs.launchpad.net/kicad/+bug/1831643
2019-06-13 16:09:45 -07:00
Ian McInerney 71f5f96e64 Remove help from F1 key and move it to an action
Create a new action in pcbnew, gerbview and the footprint viewer/
editor to display the help documentation. Disconnect the wxID_HELP
event from the window so that it no longer conflicts with the zoom
action.

Fixes: lp:1822041
* https://bugs.launchpad.net/kicad/+bug/1822041
2019-06-13 14:11:24 -04:00
Ian McInerney 2aa8e444ee Added hotkey validity checking to the preferences menu 2019-06-13 13:53:04 -04:00
Steven A. Falco cfa187f477 Show the current grid setting. 2019-06-13 12:14:41 -04:00
Wayne Stambaugh 1ed411e431 LibEdit: fix library tree refresh issue when library is removed.
A bug in LIB_MANAGER::LibraryExists() prevented a library removed from
the symbol library table from being removed from the tree view.  Add the
proper check to SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync().

This exposed another issue with synchronization between the library
table editor and the tree view which could lead to orphaned library
modifications and/or a segfault when the currently selected library was
removed from the symbol library table.  Give the user a chance to save
or revert any changes before allowing changes to the symbol library
table.

Fixes lp:1821691

https://bugs.launchpad.net/kicad/+bug/1821691

(cherry picked from commit 028973d182)
2019-06-13 08:59:26 -04:00
Seppe Stas 9233ae97d0 Set KiCad version in MacOS apps
Uses CMake's configure_file function [1] to automaticaly set the
CFBundleShortVersionString [2] value in every app's Info.plist file.

Also updates the CFBundleLongVersionString and CFBundleVersion with the
extended KiCad Version

[1]: https://cmake.org/cmake/help/latest/command/configure_file.html
[2]: https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleshortversionstring

(cherry picked from commit 455ee4c08c)
2019-06-12 14:12:01 -07:00
Seth Hillbrand 0ee38653f7 Fix default User Template location
When we assign a string to the wxFilename, it takes the last section as
the filename (unless there is a trailing '/').  So on Linux, we got
/home/user for the Documents dir and /home/ was the directory while
'user' was the filename.  Appending directories 'kicad/templates' made
the final directory '/home/kicad/templates'.  Forcing this to be a
directory restores correct behavior.
2019-06-11 13:46:10 -07:00
Seth Hillbrand df89b5bf8a eeschema: Don't extend the block when finalizing action
The block draw function is called during the mouse capture callback.  It
shouldn't be called after the block size is finalized.

Fixes: lp:1832289
* https://bugs.launchpad.net/kicad/+bug/1832289
2019-06-11 12:17:25 -07:00
Seth Hillbrand cca4037fec CMake: Another go at linear dependencies
This simplifies the linear dependencies for custom targets.  Should be
single shot for make this time.

Fixes: lp:1831643
* https://bugs.launchpad.net/kicad/+bug/1831643

(cherry picked from commit 720889edd0)
2019-06-10 14:55:01 -07:00
jean-pierre charras e015da8d95 Add a search path to allow find ngspice include dir on some msys2 installs 2019-06-10 20:42:21 +02:00
jean-pierre charras 4ceb186251 Eeschema: fix incorrect saving in prj config on the default netlist format. It was not always saved, and this was not the default, but the last used format. 2019-06-10 20:37:34 +02:00
Seth Hillbrand 370109b868 Eagle: Fix stacked NC pin import
Since Eagle does not connect stacked NC pins but KiCad will if the pins
are coincident, we choose to only import the first of the stacked NC
pins.  While this creates symbols that are slightly different in pin
count from the Eagle version, it keeps the schematic and netlist
functionally correct relative to the Eagle version.

Fixes: lp:1821319
* https://bugs.launchpad.net/kicad/+bug/1821319
2019-06-09 17:02:46 -07:00
Seth Hillbrand 3b3165ad51 pcbnew: Allow DRC violations when marked
We shouldn't consider any obstacles when we are routing in DRC violation
mode.

Fixes: lp:1826723
* https://bugs.launchpad.net/kicad/+bug/1826723
2019-06-09 13:00:13 -07:00
Seth Hillbrand 98e68cd66a Adding MIT license
The tinyspline library is under MIT, so needs to be included in our
license bundle.
2019-06-09 08:38:54 -07:00
jean-pierre charras 407301a28c Fix issue in cairo_gal when drawing a 360 deg arc (in fact a circle). It was due to a angle normalization between -360 and 360 degrees. So, in arcs, if the start angle and end angle diff is n*360 deg, this normalization gives start angle = end angle. The fix forces end angle = start angle+360deg in this case.
Fixes: lp:1832096
https://bugs.launchpad.net/kicad/+bug/1832096
2019-06-09 11:09:43 +02:00
Seth Hillbrand 5ce0e7265b modedit: Clear undo when importing
Importing a footprint is creating a new board.  Undo breaks here as we
don't maintain undo/redo across boards.

Fixes: lp:1832107
* https://bugs.launchpad.net/kicad/+bug/1832107
2019-06-08 13:05:02 -07:00
Seth Hillbrand f1704fd61a bitmap2component: Fix logic for alpha mask
For POTRACE, black is the foreground and white is the background.  We
should keep the convention by requiring the pixin to be less than the
black threshhold as well as the alpha to be at least the alpha
threshhold.

Fixes: lp:1821563
* https://bugs.launchpad.net/kicad/+bug/1821563
2019-06-08 12:03:48 -07:00
Seth Hillbrand 35e87128f5 pcbnew: Ensure cursor remains set during tool activity
Mouse capture end is called by some actions such as save board.  This
resets the cursor image but doesn't change the current tool.  Resetting
the cursor image during action prevents this.
2019-06-08 10:23:38 -07:00
Seth Hillbrand dd93f89931 Import Vector Dialog formatting
This standardizes the import vector graphics file dialog to use the
sbSizer titles instead of bold+lines.  Tooltip changes will be in the
next change as we don't change strings for bugfix releases and this
commit is targeted for 5.1.3

Fixes: lp:1823462
* https://bugs.launchpad.net/kicad/+bug/1823462

(cherry picked from commit f7550940ee)
2019-06-08 09:47:29 -07:00
Seth Hillbrand fb85612f81 eagle: Strip newlines from description
Eeschema old format is line-terminated so the newlines in descriptions
will break the schematic file if saved.

Fixes: lp:1829707
* https://bugs.launchpad.net/kicad/+bug/1829707
2019-06-07 22:08:06 -07:00
Seth Hillbrand 966173c129 pcbnew: Don't reset triangular points for intersection
We prevent the creation of invalid polygons by keeping the converging
lines from intersecting.  This test doesn't make sense for triangular
polygons as they always intersect and we want to allow them to move
outside of the singular point.

Fixes: lp:1831481
* https://bugs.launchpad.net/kicad/+bug/1831481
2019-06-07 21:35:03 -07:00
jean-pierre charras 55757039fa Custom pads: fix a bug when plotting the custom shape. This bug was seen only with some shapes, not all, and only for layers having a negative margin.
Fixes: lp:1831941
https://bugs.launchpad.net/kicad/+bug/
2019-06-07 10:51:43 +02:00
jean-pierre charras 1113e18c40 Fix incorrect initialization of some menuitems IDs.
Although is is currently working, it is a potential issue.
2019-06-06 08:01:24 +02:00
Jon Evans 02947345e8 Mathplot: properly set foreground color when saving screenshots
Fixes: lp:1810914
* https://bugs.launchpad.net/kicad/+bug/1810914

(cherry picked from commit 27a5ed1a9f)
2019-06-05 22:44:18 -04:00
Seth Hillbrand 63f18f0b03 CMake: Handle custom_target indirection
Building custom targets that depend on custom commands such as our
keyword lexer requires two layers of indirection to pick up changes
properly and not overwrite the same file in parallel builds.

Fixes: lp:1831643
* https://bugs.launchpad.net/kicad/+bug/1831643

(cherry picked from commit c6af38477d)
2019-06-05 13:10:00 -07:00
Jeff Young cd6da987cc Make sure the current desc is shown for parts being edited.
Fixes: lp:1820298
* https://bugs.launchpad.net/kicad/+bug/1820298

(cherry picked from commit 7c337ec45d)
2019-06-04 16:30:59 +01:00
Ian McInerney 006d7ddd31 pcbnew: Add context menu for measure tool
Fixes: lp:1831063
* https://bugs.launchpad.net/kicad/+bug/1831063
2019-06-02 07:57:41 -07:00
Ian McInerney 81842fc9d0 eeschema: Make symbol editor cursor track crosshairs with arrow keys
Fixes: lp:1829280
* https://bugs.launchpad.net/kicad/+bug/1829280
2019-05-31 07:47:18 -04:00
Ian McInerney ec9e0b2086 pcbnew: Fix export of edge.cuts layer to STEP format
Fixes: lp:1820841
* https://bugs.launchpad.net/kicad/+bug/1820841

(cherry picked from commit 55261eb223)
2019-05-29 19:43:16 -07:00
Jon Evans 64b71644bb Zoom to fit: only consider worksheet if there are no other items
(cherry picked from commit 04d6ec7de7e7f90482310311fcee416e8ed6410f)
2019-05-29 20:52:07 -04:00
Seth Hillbrand 1e58b09d96 Don't change the board without user action
Grid and ratsnest visibility are stored in the board file and should not
be changed without the user explicitly modifying them.

In the future, we'll move these settings out of the board file but we
shouldn't cause extra file-churn for flipped bits.

Fixes: lp:1828285
* https://bugs.launchpad.net/kicad/+bug/1828285

(cherry picked from commit e7e20b85b5)
2019-05-29 11:28:28 -07:00
Seth Hillbrand 455136ee50 eeschema: end mouse capture before exiting sheet
The mouse capture has a cleanup associated that we call to cancel the
action.  This prevents issues when trying to copy between hierarchical
sheets.

Fixes: lp:1819278
* https://bugs.launchpad.net/kicad/+bug/1819278
2019-05-28 21:19:21 -07:00
Jon Evans 1058ba6a0f PcbNew: ensure Bezier points are updated before plotting
(cherry picked from commit b060880aacfb5e2ff44dea0000733e835d0b8b2a)
2019-05-29 00:07:22 -04:00
Jon Evans f8c541c0d7 PcbNew: fix Bezier curves not having bounding boxes at startup
(cherry picked from commit 40621de3559ee3993d7193a0faee5d0a777be848)
2019-05-29 00:06:55 -04:00
Ian McInerney b485e78030 gal: Decoupled X and Y grid step sizes
Made the X and Y step sizes for the grid separate in the GAL.

Cleaned up the types inside the DrawGrid functions.

Fixes: lp:1821416
* https://bugs.launchpad.net/kicad/+bug/1821416

(cherry picked from commit 45f10fcff1)
2019-05-28 20:37:07 -07:00
Ian McInerney d8e7892081 pcbnew: Fix reload of python plugins in python 3
Update the reload function call to be python3 compatible along with
simplifying the load function to unify the loading of simple and
complex plugins.

Fixes: lp:1828595
* https://bugs.launchpad.net/kicad/+bug/1828595

(cherry picked from commit 59b729c731)
2019-05-28 17:21:00 -07:00
Wayne Stambaugh 1638c3b1c2 Eeschema: fix broken symbol library links after sheet edit.
Refresh the currently edit sheet screen symbol links when the sheet file
name is changed.

This fix was better than the previous fix as it was the same diff between
the master and 5.1 branches.

https://bugs.launchpad.net/kicad/+bug/1830315

Fixes lp:1830315

(cherry picked from commit 89ada624d3d3b28ad5ee1477b353501d46dae3a2)
2019-05-28 17:29:48 -04:00
Wayne Stambaugh 2d0e92d412 Revert "Eeschema: fix broken symbol library links after sheet edit."
This reverts commit f1a43f4977.
2019-05-28 17:07:46 -04:00
Wayne Stambaugh f1a43f4977 Eeschema: fix broken symbol library links after sheet edit.
Refresh the currently edit sheet screen symbol links when the sheet file
name is changed.

https://bugs.launchpad.net/kicad/+bug/1830315

Fixes lp:1830315
2019-05-28 14:49:02 -04:00
Michael Kavanagh 18f7d0129a Stop PNS router settings from being overwritten when switching modes
Fixes: lp:1824967
* https://bugs.launchpad.net/kicad/+bug/1824967

(cherry picked from commit 27d097a78c)
2019-05-27 16:16:55 -07:00
Jon Evans 356ccd0314 Eeschema: improve simulator behavior for two-source DC analysis
Fixes: lp:1830478
* https://bugs.launchpad.net/kicad/+bug/1830478
2019-05-27 18:13:07 -04:00
Jon Evans 4adf89b40b Improve image alpha handling in PDF and PS plotters
Fixes: lp:1825276
* https://bugs.launchpad.net/kicad/+bug/1825276
2019-05-27 12:35:12 -04:00
Jon Evans eb4aded5d6 PcbNew: Fix ordering of fab and courtyard layers
Fixes: lp:1829511
* https://bugs.launchpad.net/kicad/+bug/1829511
2019-05-27 11:54:43 -04:00
Jon Evans 5230f45658 Prevent unbalanced PTH pad labels from being hidden by drills
Fixes: lp:1829067
* https://bugs.launchpad.net/kicad/+bug/1829067
2019-05-27 11:54:43 -04:00
Seth Hillbrand b4e70e56a6 Eagle: Fix crash when importing Eagle V6
This fixes multiple issues when importing Eagle V6 files.

Crashes occured when arcs of 0-length were found and when parts were
referenced in the schematic that were not found in the library.  This
could happen if the library and schematic were different cases.

Fixes: lp:1830564
* https://bugs.launchpad.net/kicad/+bug/1830564

(cherry picked from commit 0e5cc54ec9)
2019-05-26 20:34:05 -07:00
Jon Evans cb3edf2607 PcbNew: Fix layer alpha overrides being overwritten by color changes
Fixes: lp:1827518
* https://bugs.launchpad.net/kicad/+bug/1827518
2019-05-26 20:20:31 -04:00
Jon Evans 720b26d11e Eeschema: fix worksheet and background color for printing
Fixes: lp:1820611
* https://bugs.launchpad.net/kicad/+bug/1820611
2019-05-26 14:25:57 -04:00
Jon Evans e35be13b23 Eeschema: use worksheet color when plotting
Fixes: lp:1825568
* https://bugs.launchpad.net/kicad/+bug/1825568
2019-05-26 12:21:08 -04:00
Jon Evans ba19d93df9 GerbView: Fix selection of the last two grid settings
Fixes: lp:1827642
* https://bugs.launchpad.net/kicad/+bug/1827642
2019-05-25 17:14:35 -04:00
Jon Evans 5d1dcb4387 GerbView: properly load worksheet visibility at startup 2019-05-25 16:58:10 -04:00
Jon Evans f101934909 Report actual intersection position for crossing tracks
Fixes: lp:1825588
* https://bugs.launchpad.net/kicad/+bug/1825588
2019-05-25 15:02:06 -04:00
Jon Evans ede2575018 Exclude invisible items from view bounding box for zoom-to-fit
Fixes: lp:1116457
* https://bugs.launchpad.net/kicad/+bug/1116457
2019-05-25 10:44:15 -04:00
Jon Evans fb80ee5a0e Store items changed by connectivity algorithm in undo list
Fixes: lp:1828442
* https://bugs.launchpad.net/kicad/+bug/1828442
2019-05-24 21:55:49 -04:00
Michael Kavanagh 44fc69398c Fix footprint marked as modified when layer visibility changed
Fixes: lp:1830330
* https://bugs.launchpad.net/kicad/+bug/1830330

(cherry picked from commit 741140e4a4)
2019-05-24 16:17:43 -04:00
Wayne Stambaugh c162337cab Pcbnew: Python scripting support clean up.
Always check the return value of PyRun_SimpleString() for errors when a
Python script is run and show an error message rather than fail silently.

Enable Python interpreter I/O redirection in debug builds so that script
string errors will be shown when PyRun_SimpleString() is called.

Do not call PyErr_Print() after a PyRun_SimpleString() call failure.  It
doesn't do anything useful.

Do not call Py_Finalize() after a PyRun_SimpleString() call failure.  It
seems to cause Pcbnew to crash.

(cherry picked from commit 816f6db310)
2019-05-24 08:01:57 -04:00
John Beard 821faaf3c0 Format: add some formatting aliases, improve dev docs
The aliases are easier than calling check_coding.sh manually,
and we already provide an alias file for the fixes alias, so
do the same for these.

(cherry picked from commit 241127788e)
2019-05-23 21:29:36 +01:00
Ian McInerney bf85eb9b4e pcbnew: Fixed listing of 3D libraries in the github wizard
Fixes: lp:1830137
* https://bugs.launchpad.net/kicad/+bug/1830137

(cherry picked from commit 0daf14f9c3)
2019-05-23 09:51:10 -07:00
Seth Hillbrand 691c6614a8 Plotter: Ensure group style is respected in SVG
Graphics Changed is cleared when setting graphics for a group but needs
to be reset when the group ends.

Fixes: lp:1830245
* https://bugs.launchpad.net/kicad/+bug/1830245

(cherry picked from commit 1a56dfe342)
2019-05-23 09:48:38 -07:00
Wayne Stambaugh 6db7cb8937 Symbol Editor: fix datasheet field bug loading old symbol libraries.
This only applies to the root symbol when the datasheet field is not
empty and the datasheet for root symbol alias in the document file is
empty.  Use the root symbol datasheet field value when adding a new
symbol that meets this criteria.

The root symbol datasheet field gets copied to the root symbol alias
datasheet member variable so if the symbol is modified and saved, the
datasheet information is saved in the .dcm file.

https://bugs.launchpad.net/kicad/+bug/1830078

Fixes lp:1830078

(cherry picked from commit c52ff1ca23)
2019-05-23 09:02:21 -04:00
Wayne Stambaugh 6afc572eae Eeschema: fix datasheet field bug loading old symbol libraries.
This only applies to the root symbol when the datasheet field is not
empty and the datasheet for root symbol alias in the document file is
empty.  Use the root symbol datasheet field value when adding a new
symbol that meets this criteria.

https://bugs.launchpad.net/kicad/+bug/1830083

Fixes lp:1830083

(cherry picked from commit 300f5cb082)
2019-05-23 07:35:10 -04:00
Michael Kavanagh 2a932a2176 Allow setting cursor and aux items colour in footprint editor
Fixes: lp:1829850
* https://bugs.launchpad.net/kicad/+bug/1829850
2019-05-22 15:11:20 -04:00
Seth Hillbrand b2bcde1bfc EAGLE: Correct pcb text orientation
Fixes: lp:1829711
* https://bugs.launchpad.net/kicad/+bug/1829711

(cherry picked from commit 1181b9f9b4)
2019-05-22 10:38:16 -07:00
Seth Hillbrand ec6fd23636 EAGLE: Prevent numeric-only component references
KiCad does not allow references to be numeric only.  This prefixes such
references with "UNK" to note that the reference designator type is
unknown.

(cherry picked from commit a62a89eac3)
2019-05-22 10:38:16 -07:00
Seth Hillbrand 6f34f95c52 Allow squared inflation and inflate Eagle Zones
Sometimes we want to inflate a polygon without adding rounded edges.
This add the option using the jtMiter setting.

This is used in the Eagle parser to expand the Eagle zones for KiCad.
Eagle Zones are drawn on the polygon edge, so they extend out from the
outline.  KiCad zones are drawn inside the polygon.  We need to both
increase the zone size and decrease the minimum pen width to account for
this.

Fixes: lp:1817312
* https://bugs.launchpad.net/kicad/+bug/1817312

(cherry picked from commit 490c805319)
2019-05-22 10:38:16 -07:00
Seth Hillbrand 94e5b36279 pcbnew: Allow adding SHAPE_LINE_CHAIN to zones
(cherry picked from commit bf0a466642)
2019-05-22 10:38:16 -07:00
Seth Hillbrand f0ce4d6336 eagle: Use width on imported lines if available
If not, use the current board design settings for line thickness based
on the board layer.

(cherry picked from commit c80e3e0ffc)
2019-05-22 10:33:24 -07:00
Seth Hillbrand d06b42b917 Eagle: Allow directory creation when importing
The DD_MUST_EXIST flag prevents users from creating a new directory for
their imported eagle project.  This is a UX annoyance.

(cherry picked from commit 9992839c78)
2019-05-22 10:33:09 -07:00
jean-pierre charras 764986a9b0 Fix a compil issue 2019-05-22 18:35:58 +02:00
jean-pierre charras c4efa95b4a * Eeschema: Ensure axis are always drawn in libedit and viewlib
(From master branch)
2019-05-22 17:56:08 +02:00
Wayne Stambaugh 5a655779d7 Eeschema: fix broken cursor after mouse wheel pan.
Fixes lp:1827787

https://bugs.launchpad.net/kicad/+bug/1827787
2019-05-21 14:21:53 -04:00
Wayne Stambaugh 0403437ad0 Eeschema: replace invalid characters when converting from text to label.
Fixes lp:1829664

https://bugs.launchpad.net/kicad/+bug/1829664
2019-05-20 14:49:49 -04:00
jean-pierre charras b62f94f5c2 Pcbnew: release the lock file if a board was loaded, and when clearing the board currently edited. When the board is cleared, the previous loaded board is no longer in edit. 2019-05-20 18:38:03 +02:00
jean-pierre charras daf09ed9fe Pcbnew: fix a (minor) lock file issue: the lock was too early set. If the file was (for some reason) not actually loaded, it was locked. Now, the file is locked only if it is actually loaded. 2019-05-20 18:37:49 +02:00
Seth Hillbrand 72794f1416 eagle: Use the "first" tag instead of pin num
Eagle parsing allows pin 1 to be different from the other pins in the
package but this is set by a tag marking the pin as "first" rather than
the actual number of the pin.

Fixes: lp:1829251
* https://bugs.launchpad.net/kicad/+bug/1829251

(cherry picked from commit dbc40096db)
2019-05-20 06:03:07 -07:00
Jon Evans b00e20b23f GerbView: fix saving of canvas type and lingering legacy menu item
Fixes: lp:1829647
* https://bugs.launchpad.net/kicad/+bug/1829647
2019-05-19 15:28:27 -04:00
John Beard e99a2181ff Correct Slovenian flag
The symbol was wrong (copied from Slovakian flag) and the
blue colour was not the same as the flag on Wikipedia (which
does admittedly seem contentious, but they seem to have reached
some kind of consensus).

(cherry picked from commit de055031a3)
2019-05-17 21:06:32 +01:00
Seth Hillbrand 65b38e8dcf pcbnew: Check for valid data before deleting
We need to check for valid rows and iterators before removing a 3d model

Fixes: lp:1829337
* https://bugs.launchpad.net/kicad/+bug/1829337

(cherry picked from commit f32c95229e)
2019-05-17 09:36:18 -07:00
Wayne Stambaugh 9b8780a2fd Pcbnew: fix bug in Eagle footprint plugin.
Some how a board object was required to fetch the line width when a
footprint is being parsed.  The problem is that there is no board
defined when loading Eagle footprint libraries so there was a nullptr
segfault as a result.  When there is no board defined, use the default
KiCad layer line widths.

Fixes lp:1829243

https://bugs.launchpad.net/kicad/+bug/1829243

(cherry picked from commit 97166a72f5)
2019-05-17 08:40:05 -04:00
jean-pierre charras 9c0e4cae74 Eeschema: fix incorrect position of fields of a hierarchical sheet when rotated
(From master branch)

Fixes: lp:1829048
https://bugs.launchpad.net/kicad/+bug/1829048
2019-05-17 08:36:09 +02:00
Wayne Stambaugh deb387f54c A better fix for commit d34433a1.
Replace INCREMENTAL_TEXT_CTRL with wxSpinCtrlDouble because it looks
and works better.

Remove INCREMENTAL_TEXT_CTRL header and source files because the only
place they were used was in GAL_OPTIONS_PANEL.

(cherry picked from commit f08d040c02)
2019-05-15 18:19:40 -04:00
Seth Hillbrand 5d5422b4c5 Fix default button option on close
The default is meant to be "Save" but "Discard" was selected due to ID
ordering on creation.  Setting the focus before setting the default
makes the "Save" option the highlighted option that can be selected
immediately by pressing enter.

(cherry picked from commit a0f477cc5f)
2019-05-15 14:55:12 -07:00
Seth Hillbrand 85b8dd8b34 plotter: We we trying to export mm but chose in
Note that the comment in line 142 where the scale factor was set had the
correct value to indicate metric (1) but in the actual boilerplate, we
set imperial (0).  This has been around for 6-8 years, so it would seem
DXF is not our most popular export.

Note, I initially tried to use '1' to specify metric units but this was
not handled by DXF readers (QCAM, Inkscape).  Instead, scaling the page
units to inches properly seems to work.

(cherry picked from commit 0eb391b13f)
2019-05-15 14:55:00 -07:00
Wayne Stambaugh b93d34dff4 Fix GAL display options panel spin button layout on windows.
Fixes lp:1829224

https://bugs.launchpad.net/kicad/+bug/1829224

(cherry picked from commit d34433a1df)
2019-05-15 15:01:00 -04:00
jean-pierre charras e997a7db9a Gerbview: Sync issue between the D Code drop list and the active layer
Fixes: lp:1829234
https://bugs.launchpad.net/kicad/+bug/1829234
2019-05-15 16:28:18 +02:00
Wayne Stambaugh d1a065119e Pcbnew: fix crash when deleting DRC errors from DRC dialog.
Fixes lp:1828726

https://bugs.launchpad.net/kicad/+bug/1828726

(cherry picked from commit a32bb4e9a5)
2019-05-14 18:42:03 -04:00
Mario Luzeiro 1dab468e20 Add some epsilon value to ray dir on orthographic mode
so they will not be zero when viewing the board com the top/bot.
This was causing problems with BBox intersect function that was using
invDir values.

Fixes lp:1828747
https://bugs.launchpad.net/kicad/+bug/1828747
2019-05-14 16:10:54 +02:00
Henner Zeller c5cd0c73a3 Raytracing - a more pleasing way sequencing blocks to render.
(cherry picked from commit 2aea26de1e)
2019-05-14 09:28:55 -04:00
Wayne Stambaugh ae139403e4 Fix library table editor dialog environment variable grid column names.
Fixes lp:1825977

https://bugs.launchpad.net/kicad/+bug/1828459
(cherry picked from commit 6f27ef7f66)
2019-05-14 07:59:22 -04:00
Wayne Stambaugh d3c9154f9a Fix frame name capitalization in all about dialogs.
This is a stop gap fix.  It should be possible to use the wxFrame title
string for this but some of the frame windows have appropriated the title
string for configuration file naming purposes which is less than ideal.

Fixes lp:1825977

https://bugs.launchpad.net/kicad/+bug/1825977
(cherry picked from commit 3c4f8c1bf7)
2019-05-13 16:22:52 -04:00
jean-pierre charras caba60968a Python fp wizards: fix a few issues in qrcode_footprint_wizard.py
Fixes: lp:1828744
https://bugs.launchpad.net/kicad/+bug/1828744
2019-05-13 13:26:08 +02:00
Jeff Young 2e0def8670 Defensive coding that will possibly fix a crash when scrolling through footprints.
Fixes: lp:1828289
* https://bugs.launchpad.net/kicad/+bug/1828289

(cherry picked from commit 717b1d37be)
2019-05-11 23:55:08 +01:00
Martin McNamara 8c3d16a395 PCBnew: Fixes crosshair issue with "Place Text" and "Add Dimension".
When using "Place Text" the crosshair was freezing if cancelled before
placing text.

After the crosshair freezes, the next uses of the "Place Text" or
"Add Dimension" caused the crosshair to jump to the screen location
where the previously the crosshair was frozen.

Cancelling the "Add Dimension" caused the crosshair to jump to the
screen location where the crosshair was when cancelled on the next use
of the "Place Text" or "Add Dimension".

Fixes: lp:1822578
* https://bugs.launchpad.net/kicad/+bug/1822578
2019-05-11 06:54:40 -07:00
jean-pierre charras 3f48531da7 DIALOG_EDIT_COMPONENT_IN_LIBRARY: fix a dialog resize issue (grid not resized). 2019-05-11 10:09:32 +02:00
Mark 128cdca068 Fix for SWIG 4.0.0
(cherry picked from commit 5685174808)
2019-05-10 14:38:26 -04:00
Michael Kavanagh bd997a3900 Add Save As hotkey to footprint editor
Fixes: lp:1828481
* https://bugs.launchpad.net/kicad/+bug/1828481

(cherry picked from commit a3483f44d2)
2019-05-10 15:39:33 +01:00
Wayne Stambaugh 8e93eda449 Eeschema: fix corrupted schematic and symbol library files.
Prevent user from pasting text with carriage return and/or line feed
characters in field value edit control in the schematic symbol and symbol
library properties dialogs.

Make all objects derived from GRID_CELL_TEXT_BUTTON use validators
correctly.

Add validators to FIELDS_GRID_TABLE object for field values other than
the mandatory fields.

Create a validator to check that a string is a valid LIB_ID.

Fixes lp:1828214

https://bugs.launchpad.net/kicad/+bug/1828214
(cherry picked from commit ae54f34392)
2019-05-10 09:16:38 -04:00
John Beard a6674ecd56 Pcbnew: remove SVG from menu text
The SVG importer is an advanced config. It's not supported or
normally available in 5.1, so don't advertise in the menu.

If the advanced config is enabled, the dialog will be able
to import SVG.

This could have been "Import *Vector* Graphics" like in master,
5.1 documentation will probably still say "DXF", so keep consistent.

Fixes: lp:1821571
* https://bugs.launchpad.net/kicad/+bug/1821571
2019-05-10 12:41:29 +01:00
jean-pierre charras 654651856f Custom pads: minor fix in legacy mode related to commit a155289f. 2019-05-09 16:46:13 +02:00
jean-pierre charras c489659a20 Custom pads: fix incorrect shape of masks when the shape is a polygon with holes and the mask margin is < 0. This is mainly the solder paste layer that shows this issue. This is due to the fact SHAPE_POLY_SET::Inflate does not work fine with polygons with linked holes. SHAPE_POLY_SET::InflateWithLinkedHoles it added to fix this issue.
Fixes: lp:1828287
https://bugs.launchpad.net/kicad/+bug/1828287
2019-05-09 16:24:39 +02:00
Wayne Stambaugh 18377e0c9f Developer documentation updates.
Remove version 5 road map since version 5 has been released.

Update version 6 road map to reflect current development goals.

Cleaned out old goals from generic road map in preparation for version
7 development.

Add note to compiling document about building with Boost 1.70 on Windows.

Fix link to Linux coding style policy in KiCad Coding Style Guide.

Update tool framework documentation to reflect changes in the tool
framework code.

(cherry picked from commit 3caa4376a5)
2019-05-08 08:39:00 -04:00
jean-pierre charras cebba6c0b9 Cairo GAL: fix incorrect arc position in mirror mode. the previous fix
(c56e540e5d) did not really work.

Fix from master branch.
2019-05-08 14:25:14 +02:00
John Beard 89f9bf545d All: fix horizontal touchpad panning
Commit e10c01aaf didn't work when touchpad panning was enabled.

This commit changes it to only discard horizontal wheel events
when in "scroll mode" rather than "pan mode".

Based on a patch by Adrian Scripcă <benishor@gmail.com>.

Follow-up to fix: lp:1828080
https://bugs.launchpad.net/kicad/+bug/1828080

(cherry picked from commit e6fe220f84)
2019-05-08 11:07:45 +01:00
Adrian Scripca 055d36abd7 All: fix spurious wheel scroll events caused when using modern mice.
Modern mice feature horizontal scrolling capabilities and those end
up being treated by KiCad as regular scroll events causing confusion
among users.

The fix works by discarding the handling of wheel events other than
the ones for the vertical axis.

Fixes: lp:1828080
https://bugs.launchpad.net/kicad/+bug/1828080
(cherry picked from commit e10c01aaff)
2019-05-07 17:36:23 +01:00
John Beard 7bafc5fa8b About dialog: Add mnemonics to the buttons
(cherry picked from commit 4a3add7ac5)
2019-05-07 11:15:13 +01:00
John Beard 6946c0bedb About dialog: update wxFB version
Avoid contaminating wxFB files with version fluff, which hides real
changes in the version history.

(cherry picked from commit cc28fb18fd)
2019-05-07 11:15:13 +01:00
jean-pierre charras bb40f86daa * Eeschema: fix incorrect display of the page number in a complex hierarchy.
When, inside a complex hierarchy, one switch from an instance of a sheet to an other instance of this sheet,
the page number shown in the worksheet was not updated on screen, and the initial number was displayed.

Fix from master branch.
2019-05-07 11:02:05 +02:00
John Beard 89d198659c Format: Default to switch cases on separate lines by default
Currently, the format enforces single lines when possible, but does
not enforce readable column-based alignment (and, moreover, *removes*
such manually added alignment:

    switch( m_orientation )
    {
    case PIN_RIGHT: m_orientation = PIN_UP; break;
    case PIN_UP: m_orientation = PIN_LEFT; break;
    }

Change this to multi-line by default:

    switch( m_orientation )
    {
    case PIN_RIGHT:
        m_orientation = PIN_UP;
        break;
    case PIN_UP:
        m_orientation = PIN_LEFT;
        break;
    }

If the developer wishes for column-aligned single-line cases, this
is permitted, but much be done manually:

    switch( m_orientation )
    {
    case PIN_RIGHT: m_orientation = PIN_DOWN;  break;
    case PIN_UP:    m_orientation = PIN_RIGHT; break;
    }

CHANGE: the _clang-format file to reflect this, and add note about
manual override in the dev docs.

(cherry picked from commit 272c045c37)
2019-05-07 09:50:22 +01:00
jean-pierre charras c56e540e5d Cairo GAL: fix incorrect arc position in mirror mode. It happens in print mode and also when the Pcb view is flipped.
Fixes: lp:1824720
https://bugs.launchpad.net/kicad/+bug/1824720

Fixes: lp:1822772
https://bugs.launchpad.net/kicad/+bug/1822772

Fixes: lp:1823147
https://bugs.launchpad.net/kicad/+bug/1823147
2019-05-06 11:30:15 +02:00
Seth Hillbrand d3fd74246f Merge remote-tracking branch 'andrei/pr-gitignore'
(cherry picked from commit 4d776034ca)

This also picks up an additional line from 45aa514591 that keeps
CMakeModules/*.cmake.  The rest of that commit does not merge cleanly.
2019-05-02 10:38:40 -07:00
Wayne Stambaugh 616061a6ca Eeschema: fix broken symbol library links.
Force the symbol library links whenever the symbol library table has been
modified.  This will use the cache as a fallback when a library has been
removed that contains links in the schematic rather than display.

Fix the SCH_COMPONENT symbol resolver when falling back to the cache.  The
resolver was using the LIB_ID ':' notation which was failing.  Replacing
':' with '_' fixed this issue.  This was also an issue when generating the
symbol message panel information.

Convert wxLogDebug to wxLogTrace in symbol resolver code path.  Add new
trace type KICAD_SYM_RESOLVE.

Fixes lp:1821606

https://bugs.launchpad.net/kicad/+bug/1821606
(cherry picked from commit 7d803437e2)
2019-05-02 12:13:30 -04:00
Tomasz Włostowski d94b8b9c0e router: copy m_maxClearance when cloning/branching PNS::NODEs
Fixes: lp:1813328
* https://bugs.launchpad.net/kicad/+bug/1813328

(cherry picked from commit 9e00f48efc)
2019-05-01 11:39:15 +01:00
John Beard 89d39cf8ff Pcbnew: use same null check as eeschema for recently used
When Pcbnew's add footprint browser is run up, it constructs
the recently used list without checking for nulls.

Although the DoAddLibrary call does internally check for
null, it's easier to filter these out before placing into
the vector in the first place.

The same logic in the symbol tree is already handled in the
same way.

(cherry picked from commit 42d20cbd96)
2019-04-29 17:00:42 +01:00
jean-pierre charras 0ba130dbd3 Pcbnew: fix in board editor crash when try to load a footprint from Add footprint tool if the latest loaded footprint was deleted. In this case, the history has a cleared link that created the crash when the dialog tried to select this deleted FootprintEnumerate
Fixes: lp:1826794
https://bugs.launchpad.net/kicad/+bug/1826794
2019-04-29 17:23:27 +02:00
John Beard 434935613c Eeschema: Fix/circumvert GTK3 tree view bug
There is a rendering bug in GTK3, which appears to be
an upstream GTK issue.

This can be worked around by, when filtering, ensuring the
*parent* item of the selected item is visible. This will
not cause the selected item to not be visible, as the selected
item will be the first shown child. So it will be visible, as long
as the list box is greater than a single row high, which it will be
in all practical scenarios.

This is done on all platforms, as it has a beneficial side-effect:
the parent library of the selection is naturally shown to the
user, so they don't need to scroll up to see what library their
current filter selection was in.

Fixes: lp:1804400
* https://bugs.launchpad.net/kicad/+bug/1804400

(cherry picked from commit 10900c918f)
2019-04-28 17:18:09 +01:00
John Beard 454585d3d2 GAL: add some trace to GAL display options config
This can be helpful when tracing where certain configurations
come from (some apps load from other apps' config basenames).

(cherry picked from commit fcc4a84e0e)
2019-04-27 14:58:50 +01:00
John Beard 65a6e341ad Eeschema: Symbol preview widget needs common config for Hi-DPI
Currently, this widget doesn't read the common library settings.
This means it doesn't use the configured DPI scaling or anti-aliasing
settings.

Use the ReadConfig method on the GAL options to fix (rather than
only ReadAppConfig).

Fixes: lp:1825913
* https://bugs.launchpad.net/kicad/+bug/1825913

(cherry picked from commit 33fe9a2761)
2019-04-27 14:58:50 +01:00
John Beard fc933034db Eeschema: fix resizing of pin table and edit symbol dialog
These dialogs had logic to avoid a table re-adjustment unless
the width changed. This was done to avoid spurious resizing
calls under GTK+3. This was commit
13249b723b, fixing bug lp:1817810.

However, by only calling event.Skip() when the width changed,
redraws were inhibited when only the height changed.

Placing the Skip() outside the width-change check fixes this,
and does not re-introduce the lp:1817810 bug (it is the column
adjust call that causes that).

Fixes: lp:1826615
* https://bugs.launchpad.net/kicad/+bug/1826615

(cherry picked from commit eccadd92fb)
2019-04-27 14:12:00 +01:00
John Beard 20c8b094d6 SHAPE_ARC: Fix bug introduced in 5813164d1.
This fixes the bug exposed in the previous commit.
The tests which exposed it now pass and expected failures
removed.

(cherry picked from commit d89d0e6b74)
2019-04-25 23:51:01 +01:00
John Beard 552ddfbdfa SHAPE_ARC: Expose bug introduced by 5813164d1 in tests
The angle needs to be added to the start angle.

Add tests to cover this:

* Check end point is correct
* Check midpoints are within tolerance

This would have prevented the bug fixed in 5813164d1,
as well as the bug fixed in this commit.

As well as failed tests, this manifests when routing across
Edge.Cuts arcs (unless they happen to start at 0 degrees
staritng angle).

Expose as expected failure to prove tests catch it.
Fix to follow in separate commit.

(cherry picked from commit 183f4fe9a5)
2019-04-25 23:51:01 +01:00
Tomasz Włostowski 9743eec3ab SHAPE_ARC: fixed polyline conversion bug introduced in e312e2b286
Fixes: lp:1826278
* https://bugs.launchpad.net/kicad/+bug/1826278

Fixes: lp:1826270
* https://bugs.launchpad.net/kicad/+bug/1826270

(cherry picked from commit 5813164d15)
2019-04-25 23:51:01 +01:00
Michael Kavanagh b3ad1dc26e PL editor: fix delete hotkey behaviour
Fixes: lp:1819419
* https://bugs.launchpad.net/kicad/+bug/1819419
2019-04-25 20:27:10 +02:00
Seth Hillbrand b6c9d4a88c Add missing header to qa
(cherry picked from commit 9c00a7a5c3)
2019-04-24 14:33:28 +01:00
Wayne Stambaugh 25b6ac61cb Begin version 5.1.2 development. 2019-04-22 17:16:51 -04:00
Wayne Stambaugh 9c9252e8a3 Tag release version 5.1.2. 2019-04-22 17:14:54 -04:00
John Beard 3a744ad72f Use old-style boost includes
The Boost::boost style library dependencies don't work
on some CMake versions (couldn't find library -lBoost::boost)

Use ${Boost_INCLUDE_DIRS} in the target_include_dirs() instead.

Cherry-picked (with changes) from: 1a9aa2e92d
2019-04-22 01:10:50 +01:00
jean-pierre charras 554e2a4bce qfn_wizard.py fixes. 2019-04-21 14:08:01 +02:00
Jeff Young 6e8979d8d8 Add try/catch block around writing a new library.
Fixes: lp:1825203
* https://bugs.launchpad.net/kicad/+bug/1825203

(cherry picked from commit 2bcf38d2b6)
2019-04-18 22:02:24 +01:00
jean-pierre charras 583d416640 DIALOG_CONFIGURE_PATHS: do not allow users to define the env var KIPRJMOD It always defines the project path, and should never be defined by users.
Fixes: lp:1824912
https://bugs.launchpad.net/kicad/+bug/1824912
2019-04-17 14:55:14 +02:00
jean-pierre charras 03b50b4f85 BOARD_NETLIST_UPDATER: fix 2 serious issues in dry run (memory leak and incorrect single pad nets deletion) Single pad nets deletion in dry run was incorrect when a new footprint was added, because in dry run it is not actually added, and the single pad nets deletion does not see these new pads, and can (incorrectly) delete some nets. 2019-04-17 14:55:13 +02:00
John Beard 440e135e3a QA: Remove expected failure from fixed tests
Commit 55fcbddde8 fixed a couple of
failures in the SHAPE_POLY_SET tests, so these no longer
need the expected failure markers.

(cherry picked from commit 371149756d)
2019-04-17 11:48:11 +01:00
John Beard ab39f06003 SHAPE_ARC: fix polyline conversion when radius=0
Prevent a divide-by-zero bug in SHAPE_ARC::ConvertToPolyline.

When the radius is zero, just use the initial angle (it makes
no different anyway, the result is the centre point, which is
the start point.

(cherry picked from commit e312e2b286)
2019-04-17 11:29:28 +01:00
John Beard 98f78f534c QA: Test arc to polylines - this has a bug
Add unit test of SHAPE_ARC::ConvertToPolyline.

This function has a bug when the arc is of zero radius. This
test shows the bug, but does not fix it yet.

(cherry picked from commit ce84c19a38)
2019-04-17 11:29:28 +01:00
Jon Evans d18b12c1a3 Hide simulator settings tabs that aren't implemented yet
Calling Hide() is apparently not enough in Windows

(cherry picked from commit 895d4c9e1a)
2019-04-15 23:21:31 -04:00
Simon Richter 6a7b1aa39a List Boost as a dependency for kicad2step
This is not technically correct (the Boost dependency is introduced through
libcommon), but less invasive as it doesn't pull in libcommon on the linker
command line.
2019-04-15 23:43:42 +01:00
Seth Hillbrand c4be74a9d0 eeschema: Prevent invalid '0' element in components
In the component, an m_unit/m_convert element is 1-indexed as opposed to
the library where they are 0-indexed.  The 0-index in the library is
reserved for those elements that are shared across all conversion/unit
whereas it is invalid for the component.

Fixes: lp:1824764
* https://bugs.launchpad.net/kicad/+bug/1824764
2019-04-15 12:32:29 -07:00
John Beard 9092048dbc Kicad2Step: handle quoted layers
More recent Kicad_pcb files have quoted layer names (i.e.
strings, not symbols). The importer in K2S doesn't handle that,
so it chokes on elements like (layer "Edge.Cuts").

Fixes: lp:1824750
* https://bugs.launchpad.net/kicad/+bug/1824750

(cherry picked from commit c135158364)
2019-04-15 15:01:57 +01:00
Wayne Stambaugh bb419f1201 Begin version 5.1.2 development. 2019-04-14 15:36:47 -04:00
Wayne Stambaugh d505fd2b60 Tag release version 5.1.1. 2019-04-14 15:32:40 -04:00
Jon Evans a771e0eccb Set new module parent early enough to allow pad clearance to be shown
Fixes: lp:1824587
* https://bugs.launchpad.net/kicad/+bug/1824587
2019-04-14 14:26:15 -04:00
Jon Evans 593a5181d7 Fix rotation of global and hierarchical labels
Fixes: lp:1824432
* https://bugs.launchpad.net/kicad/+bug/1824432
2019-04-13 17:02:33 -04:00
Jon Evans c29274e760 Fix ngspice nested DC sweep command
Fixes: lp:1824336
* https://bugs.launchpad.net/kicad/+bug/1824336
2019-04-13 16:38:31 -04:00
Jon Evans 216573bf48 Fix ngspice netlisting when net names contain '/'
Fixes: lp:1821502
* https://bugs.launchpad.net/kicad/+bug/1821502
2019-04-13 15:35:00 -04:00
Jon Evans 1c235a5c89 Properly initialize sheets when loading them from ERC dialog
When displaying a sheet from this path, it's possible the sheet will
not have been initialized yet.  Call DisplayCurrentSheet() to make sure
it is initialized, and then call RedrawScreen to update the zoom level.

Fixes: lp:1824362
* https://bugs.launchpad.net/kicad/+bug/1824362
2019-04-13 12:25:06 -04:00
Jon Evans f90049dd9e Veto mouse warping from DRC dialog
Fixes: lp:1824630
* https://bugs.launchpad.net/kicad/+bug/1824630

(cherry picked from commit dec5d80180)
2019-04-13 11:30:21 -04:00
Jeff Young 90787e84bf Allow dialogs to veto mouse-warping when called from context menu.
Fixes: lp:1745731
* https://bugs.launchpad.net/kicad/+bug/1745731

(cherry picked from commit adf3637476)
2019-04-13 11:30:09 -04:00
John Beard c36c80a077 Fix GAL option spin button layout
These need to not be wxEXPAND and to be vertically centred
to match the adjacent text controls.

Fixes: lp:1804461
* https://bugs.launchpad.net/kicad/+bug/1804461

(cherry picked from commit 203019d959)
2019-04-12 23:36:56 +01:00
Jon Evans 227333239f Improve selection behavior of DRC markers in DRC dialog list 2019-04-12 12:58:47 -04:00
John Beard 2d43fcf9ee GAL opts: move config reading into GAL_DISPLAY_OPTIONS
Move repeated GAL config reading routines into GAL_DISPLAY_OPTIONS.
THe app-level config is in here already, do the same for the
common config.

This means that the configs are loaded consistently, which fixes
the symbol-chooser preview window, which previously didn't use the
same config routine as other GAL canvases.

Future work could move these functions to free functions that
act on the public interface of GAL_DISPLAY_OPTIONS to avoid
GAL_DISPLAY_OPTIONS having to know about wxConfig and wxWindow.

Fixes: lp:1824524
* https://bugs.launchpad.net/kicad/+bug/1824524

(cherry picked from commit ab2281d26f)
2019-04-12 16:48:50 +01:00
Jeff Young 3edad56e6b Refocus control after doing our little raise/raise dance.
Fixes: lp:1821451
* https://bugs.launchpad.net/kicad/+bug/1821451

(cherry picked from commit 4020b5689b)
2019-04-12 00:30:50 +01:00
John Beard 4e2d900775 Pcbnew: FOOTPRINT_PREVIEW_PANEL passes reference to local
Previously, the GAL_DISPLAY_OPTIONS object in FOOTPRINT_PREVIEW_PANEL::New
was passed by reference in the ctor, down to EDA_DRAW_PANEL_GAL, which stored
it as a reference. The object in New() then goes out of scope, so the
referencing panel outlives the options.

Fix this by making a copy in a std::unique_ptr of the options, and giving
ownership to the panel.

There is another issue here: when the Pcbnew options are copies, the
OBSERVABLE subscriber list is copied too. This means if the panel called
NotifyChanged() on the options, Pcbnew would get updates, even though a copy
of the options changed. However, the panel doesn't change the options or
notify, so it's OK for now.

(cherry picked from commit 17e88d0944)
2019-04-11 17:14:07 +01:00
Jeff Young 4dae82054e Increase GervView layers to 51.
This also makes its use of LSET consistent with PCBNew.

Fixes: lp:1809019
* https://bugs.launchpad.net/kicad/+bug/1809019

(cherry picked from commit b7c12b238f)
2019-04-10 21:23:29 +01:00
Jeff Young cb5948d3a5 When checking for duplicate aliases look in the dialog not the symbol.
Fixes: lp:1821543
* https://bugs.launchpad.net/kicad/+bug/1821543

(cherry picked from commit e90452d0e2)
2019-04-10 21:23:14 +01:00
jean-pierre charras 9fc7281fab Zone filler: fix missing calculation of filled polygons when fill mode is ZFM::SEGMENTS 2019-04-10 18:13:15 +02:00
Seth Hillbrand bb779b237a 3d-viewer: Refresh raytracing on rotate
(cherry picked from commit 89d2e67e45)
2019-04-09 15:18:48 -07:00
Seth Hillbrand 1294b4fec8 3d-viewer: Force canvas refresh before screenshot
In some linux configurations, the canvas refresh must be posted before
being handled.  Simply requesting the refresh can queue the event,
preventing an up to date GL canvas from being saved.

Fixes: lp:1819536
* https://bugs.launchpad.net/kicad/+bug/1819536

(cherry picked from commit 707e7b4b65)
2019-04-09 14:47:54 -07:00
Seth Hillbrand 0b754562f6 pcbnew: Handle missing footprint wizards
When we do not have any footprint wizards to display, we cannot select
the grid rows.

Fixes: lp:1823608
* https://bugs.launchpad.net/kicad/+bug/1823608

(cherry picked from commit 7cf394e34f)
2019-04-09 12:07:08 -07:00
Jeff Young 15cb032ab7 Readjust Edit Symbol Properties when symbol references changes.
The new reference may contain different numbers of units and/or
different deMorgan conversion settings.

Fixes: lp:1822316
* https://bugs.launchpad.net/kicad/+bug/1822316
2019-04-09 17:02:29 +01:00
jean-pierre charras c85d2fd3bf Pcbnew: fix a serious issue in ZONE_FILLER. 2019-04-09 16:34:38 +02:00
Wayne Stambaugh bc821ff47d Eeschema: fix schematic text object plotting issue.
Save and restore text thickness in SCH_TEXT::Plot() function to prevent
the plotting default thickness value from stepping on the original text
thickness and causing all of the text objects to magically change to bold.

Fixes lp:1823165

https://bugs.launchpad.net/kicad/+bug/1823165
(cherry picked from commit 3d33cba574)
2019-04-09 10:18:08 -04:00
Jeff Young 42d9f42807 Allow no-connects to be dragged.
Fixes: lp:1821342
* https://bugs.launchpad.net/kicad/+bug/1821342

(cherry picked from commit c78c3c8198)
2019-04-09 11:20:03 +01:00
Jeff Young 7ceff4cf5d Trim zone fills to board outline.
Fixes: lp:1820306
* https://bugs.launchpad.net/kicad/+bug/1820306

(cherry picked from commit 52e3a1d7c4)
2019-04-09 11:20:03 +01:00
Jeff Young 4147da312b Adjust justified text for rotation.
Fixes: lp:1823090
* https://bugs.launchpad.net/kicad/+bug/1823090

(cherry picked from commit a81512ca96)
2019-04-09 00:36:17 +01:00
Jeff Young 439891c31f Adjust left- or right-justified text for mirroring.
(cherry picked from commit 97063440bb)
2019-04-09 00:36:06 +01:00
John Beard 322524101d Libeval: consistent formatting for NaN
On some platforms like MSVC, NaN prints as "-nan(ind)". This
is a bit needlessly ugly, so print "NaN" on all platforms
consistently.

This fixes a test failure on MSVC.

(cherry picked from commit dd17f24c04)
2019-04-08 16:29:24 +01:00
John Beard fd698653d9 QA: numeric evaluator: add a context to tests
This allows a failing test to report which case failed more clearly.

Add a quick helper to make an "in -> out" context string.

(cherry picked from commit 3f32dc9a64)
2019-04-08 15:58:59 +01:00
John Beard 8b503a06fa 3D viewer: update icons from common settings
Use the icon scaling logic and call a toolbar rebuild when the
common settings change (echos the handling in Pcbnew and friends).

Remove an unused function.

(cherry picked from commit 8548e69382)
2019-04-08 14:30:26 +01:00
John Beard 4a201df556 3D viewer: use hi-DPI settings for canvases
The 3D viewer also uses OpenGL, so it also needs to
adjust based on DPI scale factors.

This patch moves the 3D viewer common config code solely
within the 3D viewer, and adds handling of the DPI scale. This
also avoids duplicated logic in PCB_BASE_FRAME::CommonSettingsChanged.

For now, as EDA_3D_VIEWER is not included in the Kiway settings
dispatch, still manually invoke the settings update from
PCB_BASE_FRAME.

The PANEL_3D_PREV gets a similar function to read the config, but
it doesn't have a listener for the update, so it's set just once
at dialog init, just like the existing pan settings.

Fixes: lp:1823681
* https://bugs.launchpad.net/kicad/+bug/1823681

(cherry picked from commit 124dd5e59a)
2019-04-08 14:30:26 +01:00
Seth Hillbrand 577b9f478b pcbnew: Show clearance when editing tracks
When requested by display options, we should show the track clearance
when dragging tracks.

Fixes: lp:1818343
* https://bugs.launchpad.net/kicad/+bug/1818343

(cherry picked from commit cf63ae7ae2)
2019-04-07 21:26:06 -07:00
Seth Hillbrand f5a2eb1ab0 pcbnew: Allow click+drag of tracks
This behavior existed in 5.0.x but did not properly exit the edit tool
in 5.1.  This removes stops the edit tool when we begin dragging a track
using the interactive router.

Fixes: lp:1820312
* https://bugs.launchpad.net/kicad/+bug/1820312

(cherry picked from commit c8118e3ce4)
2019-04-07 20:59:38 -07:00
Michael Kavanagh 4379480d4b Change "Switch track width to previous" default hotkey from Ctrl+W to Shift+W
Tiny improvement in consistency.

Fixes lp:1785842
https://bugs.launchpad.net/kicad/+bug/1785842

(cherry picked from commit 27e6f5b9e8)
2019-04-07 10:52:15 -07:00
Seth Hillbrand dfa4afa826 pcbnew: Freeze the netclasses dialog on init
Prevents the size events from firing on Mac when we set up the netclass
panel

Fixes: lp:1819426
* https://bugs.launchpad.net/kicad/+bug/1819426

(cherry picked from commit a300ae105d)
2019-04-07 07:08:35 -07:00
Wayne Stambaugh a533514763 Minor symbol library rescue dialog fixes.
Adjust the sizer proportions slightly to eliminate the reported bug.
This may not be the ideal way to do this and there could be some issues
on other platforms but it does resolve the issue on gtk3.

Fixes lp:1820084

https://bugs.launchpad.net/kicad/+bug/1820084

(cherry picked from commit 615c49315f)
2019-04-06 08:19:06 -04:00
Wayne Stambaugh 952aaef52a Minor drill file dialog improvements.
(cherry picked from commit b6a0bf1142)
2019-04-05 16:49:51 -04:00
Wayne Stambaugh a54016a6f7 Minor footprint position dialog improvements.
(cherry picked from commit dfee7bddd3)
2019-04-05 16:17:00 -04:00
Michael Kavanagh 0c8a95c44b Invert maximum and minimum endpoints on color picker sliders
Put the maximum values at the "top" of the sliders.

Fixes: lp:1823196
* https://bugs.launchpad.net/kicad/+bug/1823196

(cherry picked from commit 1ccef6dc80)
2019-04-05 14:38:48 +01:00
John Beard 403633d21f Regenerate DIALOG_COLOR_PICKER_BASE wxFB files
This avoids the wxFB automatic changes hiding substantive changes
to be made in later commits.

(cherry picked from commit 0f39d4907f)
2019-04-05 14:38:48 +01:00
jean-pierre charras cc6f1d784d DIALOG_COPPER_ZONE: fix bug that prevent to convert a zone filled by segments to a zone filled by solid polygons 2019-04-05 10:21:16 +02:00
Wayne Stambaugh e07ef3be9c Minor schematic formatter fix.
Apparently at some point in KiCad's development, a '~' character was
prefixed to the symbol name to indicate that it was not visible.  The
visibility state is now saved in the name field so remove the prefix.
The parser was kept unchanged.

Fixes lp:1632048

https://bugs.launchpad.net/kicad/+bug/1632048

(cherry picked from commit ee14da3093)
2019-04-04 10:50:23 -04:00
jean-pierre charras f35f534ff4 DIALOG_PAD_PROPERTIES: Fix incorrect calculation of Round Rect Radius Ratio, when inches are selected.
Fix from master branch.
2019-04-04 15:56:06 +02:00
Jeff Young 3899ec136b Use a bigger hammer when refreshing fields in table.
Fixes: lp:1823050
* https://bugs.launchpad.net/kicad/+bug/1823050
2019-04-04 12:27:29 +01:00
Seth Hillbrand 91ee809558 pcbnew: Prevent aux axis after-image
Grid helper in the router tool is persistent, so remember to turn off
the aux axes after setting.

Fixes: lp:1822577
* https://bugs.launchpad.net/kicad/+bug/1822577

(cherry picked from commit 428e7a900b)
2019-04-03 16:27:37 -07:00
jean-pierre charras 4c94e2729f geometry/geometry_utils.cpp: Fix a minimal value (6) to calculate the segments by circle count to approximate a circle.
Use also this minimal value to calculate  the circle to poly correction factor
Also, remove a useless code.

(cherry picked from commit 0d2dd48cad)
2019-04-03 16:25:52 -07:00
Seth Hillbrand 2a5a207148 pcbnew: Update points before refresh
When removing a point from the polygon, the vertex is removed before it
is tested for validity.  If it fails validation, the edit is reverted
and the point count doesn't change, so the view update only modifies the
existing points.  But the revert may also have changed the shared
pointer to the point array, invalidating the view's copy.

Fixes: lp:1821909
* https://bugs.launchpad.net/kicad/+bug/1821909

(cherry picked from commit 940aef77af)
2019-04-03 16:13:20 -07:00
Seth Hillbrand c75bd89d63 GAL: Deal with thick circles
Both Cairo and OpenGL had issues (different, though) with circles that are
thicker in line width than they have radius.  This corrects the OpenGL
implementation (radius is calculated to the outer edge) as well as Cairo
(line width needs to be clamped to twice the radius)

Fixes: lp:1822765
* https://bugs.launchpad.net/kicad/+bug/1822765

(cherry picked from commit db0523626c)
2019-04-03 16:03:49 -07:00
Seth Hillbrand f58844bf8b pcbnew: Allow Missing legacy option
LEGACY is disabled for GTK3, so we may not find the menu item

Fixes: lp:1822877
* https://bugs.launchpad.net/kicad/+bug/1822877

(cherry picked from commit ce254d1061)
2019-04-03 16:03:21 -07:00
Wayne Stambaugh 07ac3499f3 Remove debugging code added in commit d2cb0ca7.
(cherry picked from commit 75366bce74)
2019-04-03 12:20:37 -04:00
Wayne Stambaugh 050b64b822 Pcbnew: fix DXF import line width bug.
There is a circular dependency between the GRAPHICS_IMPORTER object and
the GRAPHICS_IMPORT_PLUGIN object which makes sharing the settings in
the GRAPHICS_IMPORTER unwieldy.  This fix is a ugly hack that resolves
the issue.  The underlying issue will require some major refactoring.

Fixes lp:1821234

https://bugs.launchpad.net/kicad/+bug/1821234

(cherry picked from commit 120ab06db4)
2019-04-03 11:32:30 -04:00
Wayne Stambaugh 43aa94dcfc Pcbnew: fix import graphics dialog issues.
Improve padding, spacing and alignment of dialog layout.

Fix title capitalization.

Make file dialog wildcard string translatable.

Remove fixed initial dialog size to allow sizers to work their magic.

Replace OK button event handler with TransferDataFromWindow.

Remember last line width units between dialog instances and sessions.

Save configuration file settings in a separate group and remove GfxImport
prefix from the entry names.

Add fencing to dialog header file to prevent nested includes.

Fixes lp:1822568

https://bugs.launchpad.net/kicad/+bug/1822568

(cherry picked from commit d2cb0ca75f)
2019-04-03 11:32:09 -04:00
John Beard b2e54a432b QA: Use own unit test headers for eagle test
These include the appropriate "polyfills" for things like
Boost versions.

(cherry picked from commit 20d36c18350fcccb1bee835553a68da8a0c96b0b)
2019-04-02 23:31:33 +01:00
John Beard e766732020 QA: Eagle test: look up test data in the source tree
Also provide a utility function to get this path, and
a way to override at run time to quickly sub in alternative
data.

The test itself is still broken, as this plugin won't accept
a call to Load() without a KiWay.

(cherry picked from commit 88faac309f)
2019-04-02 19:08:26 +01:00
John Beard 3a5e01c44a QA: Enable eeschema tests
Redesignate the eagle test as eeschema tests and build
more like the other unit tests.

Enable as a test in Ctest now that the test executes without
crashing.

The loading of the file with the hardocded part is still
not enabled, as this needs more infrastructure to support it.

(cherry picked from commit 4eb30f6b85)
2019-04-02 19:08:26 +01:00
John Beard d4883da98b Eeschema: construct simulator cursors on demand
Statically constructing wxCursors as used for the probe
and tune cursors crashes the qa_eagle_plugin test
instantly.

Fix this by introducing a new class CURSOR_STORE,
which allows to abstract the platform wierdness of wxCursors
and allow the simulator to laziliy init its own cursors
at runtime.

This code isn't properly tested, as these cursors are never
actually used. However, it does allow the eeschema unit test
to run.

Fixes: lp:1781191
* https://bugs.launchpad.net/kicad/+bug/1781191

(cherry picked from commit 6f1c3f5ef8)
2019-04-02 19:08:26 +01:00
Michael Kavanagh 7cc3e9a16d Add Ctrl+, hotkey to preferences dialog
Also change interactive router settings from Ctrl+, to Ctrl+Shift+,

(cherry picked from commit b0674b8802)
2019-04-02 13:17:37 -04:00
Michael Kavanagh 9ad352d4bd Fix 'hokey' -> 'hotkey' typo
(cherry picked from commit fe6bc411dd)
2019-04-02 13:17:18 -04:00
Seth Hillbrand 031173bc47 pcbnew: Handle old stable translated layers
This inserts a translation map in the layer names so that the old stable
files with Italian/French layer names get updated to the standard
English layer names (instead of not opening).

Fixes: lp:1370575
* https://bugs.launchpad.net/kicad/+bug/1370575

(cherry picked from commit 6f4d1345f3)
2019-04-01 14:25:27 -07:00
Seth Hillbrand 658820a25e pcbnew: Ensure DRC circles have at least 4 points
This prevents invalid outline errors for small circles.

Fixes: lp:1822641
* https://bugs.launchpad.net/kicad/+bug/1822641

(cherry picked from commit 5eb2a33498)
2019-04-01 14:25:27 -07:00
Wayne Stambaugh 17fdce01a9 GerbView: remember last open gerber file dialog wildcard.
This is only for the current GerbView session.  When GerbView is closed,
the last open gerber file dialog wildcard setting is lost.

(cherry picked from commit f20a1314ff)
2019-04-01 12:47:45 -04:00
Jeff Young bc4cc00332 Update description when tree item is in editor.
Fixes: lp:1820298
* https://bugs.launchpad.net/kicad/+bug/1820298
2019-04-01 13:47:40 +01:00
Jeff Young b57e9492b1 Disable alias controls when no alias is selected.
Fixes: lp:1821698
* https://bugs.launchpad.net/kicad/+bug/1821698
2019-04-01 13:47:31 +01:00
Jeff Young 712bdc9d8d Set initial focus to track width / via size.
Fixes: lp:1822177
* https://bugs.launchpad.net/kicad/+bug/1822177
2019-04-01 13:47:22 +01:00
Jeff Young 33a7c95455 Remove angle brackets from indeterminate string.
They don't really help any, and they confuse some users into
thinking they need angle brackets around real values.

Fixes: lp:1821601
* https://bugs.launchpad.net/kicad/+bug/1821601
2019-04-01 13:47:13 +01:00
Jeff Young f054dcc77d Allow save after importing footprint.
Fixes: lp:1819777
* https://bugs.launchpad.net/kicad/+bug/1819777
2019-04-01 13:47:02 +01:00
Jeff Young 95858b77c1 Ignore BRIGHTENED state when printing.
Fixes: lp:1788480
* https://bugs.launchpad.net/kicad/+bug/1788480
2019-04-01 13:46:46 +01:00
Jeff Young 4afbce5ad6 Fixes for importing board setup properties.
Save/restore default netclass.
Read layers back in with correct syntax ('.' between keyword and layer name).
Write layers to project file.
Read/write layer enablement bits.
Don't set solder paste margin min to 0 (most of them are negative).

Fixes: lp:1811990
* https://bugs.launchpad.net/kicad/+bug/1811990
2019-04-01 13:46:33 +01:00
Wayne Stambaugh 93956002ac Tag version 5.1.0-dev. 2019-04-01 13:32:55 +01:00
Wayne Stambaugh 006dd290e9 Revert "appdata.xml: Remove additional license metadata"
This reverts commit 8a7e501fe6.
2019-03-31 14:35:26 -04:00
Michael Kavanagh fb875145aa Read Footprint Library Browser grid settings from Footprint Editor.
Implements commit 3a0dbf48c8 for Footprint Library Browser/Editor.

Fixes: lp:1822401
https://bugs.launchpad.net/kicad/+bug/1822401
(cherry picked from commit a611269975)
2019-03-31 07:07:52 -07:00
jean-pierre charras 77993ced7e Symbol editor, DIALOG_LIB_EDIT_PIN_TABLE: fix crash when trying to delete a pin when the table is empty.
Fixes: lp:1822406
https://bugs.launchpad.net/kicad/+bug/1822406
2019-03-30 09:32:32 +01:00
jean-pierre charras e1f64d6283 Kicad and Gerbview: add .nc and .xnc file ext to files seen as drill files. .nc is an other usual Excellon drill file ext, and .xnc will be soon also in use. 2019-03-30 09:32:32 +01:00
John Beard 2b60ce484e Formatting: prefer a Git config variable to env var
The keeps all the formatting config together in the Git ecosystem
and keeps the config on a per-repo basis, unless the user explicitly
sets it --global.

Keep the old env var behaviour for now for backwards compatibility.

(cherry picked from commit a7270f8c1c)
2019-03-29 15:12:36 +00:00
John Beard a21b336138 Formatting: exclude generated files from git formatting hook
Add a .gitattributes files to provide a place to store file
attributes. Add a custom attribute for files that should be under
KiCad style guidelines.

Exclude generated files from the style enforcement. So far:

* bitmap .cpp files
* wxFormBuilder base classes
* Lemon grammars

It's now trivial to add the 'generated' attribute to any such
file.

Putting this into .gitattributes also means it can be retreived
programmatically, by other scripts, git alaises or on the command
line.

Use the attributes to provide a utility script to show or apply
formatting to controlled files (plain git clang-format won't
pick up our custom git attributes). Add details for the script in
the dev docs.

Also modiify the check-format hook to follow the .gitattributes
and only apply to cached (staged for commit) changes. Then you
won't be stopped committing because of bad formatting in unstaged
changed, or uncontrolled files.

Concept and some aspects of the implementation inspired by
CMake commit d5f39a56 [1].

[1]: https://gitlab.kitware.com/cmake/cmake/commit/d5f39a56a44fe061018c6acc15e1c3aa7337ff54

tool

(cherry picked from commit a69cdf1793)
2019-03-29 15:12:36 +00:00
John Beard 0655280f2c QA: nullptr_t -> std::nullptr_t
This fixes a build failure on some systems.

(cherry picked from commit 49d75e2383)
2019-03-29 12:49:16 +00:00
John Beard 2793578dcb QA: Allow BOOST_CHECKing of nullptr_t
Before Boost 1.64, there was no test logging function
for std::nullptr_t.

Add a logging struct to Boost to deal with this, and some
macros to assist in similar cases. These macros are bit
untidy-looking, but due to GCC bug #56480, we can't use
namespace aliasing to solve this. From Boost 1.64 onwards,
these namespaces are not needed at all.

Remove some code added to work around lack of nullptr printing
in the past.

These macros, and the nullptr printer, can be removed when
the Boost min version is 1.64 or greater.

(cherry picked from commit ad76ebd82a)
2019-03-29 10:11:19 +00:00
Wayne Stambaugh f1a70662c5 Eeschema: do not merge graphical lines with different attributes.
Fixes lp:1821728

https://bugs.launchpad.net/kicad/+bug/1821728

(cherry picked from commit 2447933b54)
2019-03-28 13:47:58 -04:00
Carsten Schoenert 8a7e501fe6 appdata.xml: Remove additional license metadata
The extra field metadata is not really needed nor helpful as various
other additional licenses are used within the KiCad project.
All used licenses are documented with the file LICENSE.README within top
root folder of the source.

(cherry picked from commit e5de787f88)
2019-03-27 14:50:23 -04:00
Carsten Schoenert 86fc2dc2ba Adding license text for CC-BY-SA-4.0 for completeness
As for the other used licenses adding also the license content for the
CC-BY-SA-4.0 license.

(cherry picked from commit 54aed9b17e)
2019-03-27 14:50:05 -04:00
Carsten Schoenert 9cff42b4ed Adding license information for demo files
The demo files are covered by the CC-BY-SA-4.0 license.
Please note some discussion about this on the developers mailing list:

https://lists.launchpad.net/kicad-developers/msg39174.html
(cherry picked from commit 444050c7d5)
2019-03-27 14:49:44 -04:00
John Beard 55546126a1 Clang-format: break after templates
Enforce the following format:

template<>
void function<TYPE>()

Rather than:

template<> void function<TYPE>()

This is the more common format in KiCad (about 8:1) and agrees
with the uncrustify.cfg rules.

(cherry picked from commit 3536840f52)
2019-03-27 14:38:52 +00:00
John Beard 5a11dacd9e Pcbnew: Improve tab traversal in text properties dialog
Tab through the grid vertically, then horizontally, as the fields
are laid out with "related" fields (like the co-ords) vertically.

Also neaten headers.

Fixes: lp:1821887
* https://bugs.launchpad.net/kicad/+bug/1821887

(cherry picked from commit d6b8e9e037)
2019-03-27 14:06:16 +00:00
John Beard bb5873bf20 Pcbnew: Align right margins in text properties dialog
(cherry picked from commit b7017167f0)
2019-03-27 14:06:16 +00:00
John Beard 20eda54349 Pcbnew: update text properties dialog wxFB version
No actual changes, but this keeps the diffs clean(er).

(cherry picked from commit dd3252445d)
2019-03-27 14:06:16 +00:00
Michael Kavanagh c98461f59e Open drill file in gerbview from KiCad manager tree
Fixes lp:1819754
https://bugs.launchpad.net/kicad/+bug/1819754

(cherry picked from commit b681e4a68e)
2019-03-27 09:13:23 -04:00
jean-pierre charras b154c9a5c4 Eeschema: Force time stamp to 32 bits unsigned values, and make it
tolerant to files using 64 bits values. define timestamp_t as uint32_t.

This fix is adapted from master, commit 175a2bc0b (bug fix lp:1821476)
2019-03-27 13:17:54 +01:00
jean-pierre charras 12255e3680 Eeschema: fix incorrect handling of Escape key. Key events do not have to be skipped after they are handled. 2019-03-27 13:17:54 +01:00
John Beard 473c41ddbf Eeschema: internal tidying of field editor ApplyData
Make a few things const (specficially the reference into
m_fieldStore - we should commit to not modifying that in this
function.

Also avoid a couple of needless string copies.

Also explicitly dereference the into a (non-const) reference at the outset.
For the whole if this function, comp is the same object and may not
be null (as it is used unchecked).

(cherry picked from commit edd94ce2d6)
2019-03-27 10:29:36 +00:00
Baranovskiy Konstantin b93382831c Eeschema: place new field near parent component
For now fields created in Fields Editor are placed at
position (0, 0).
Every new field must be placed at the origin of
the parent component.

(cherry picked from commit 11f03c8551)
2019-03-27 10:29:36 +00:00
Michael Kavanagh 5ee61f5ae7 Fix mnemonic typo in pcbnew menubar
(cherry picked from commit bbcea3c98d)
2019-03-26 19:19:11 -04:00
Seth Hillbrand 082bbd49e7 sim: Prevent stepping
Introduced by 416e64a334.  The code
appears to have been stepped on purpose but this would be incorrect for
most applications.  There remains a good deal of cleanup in mathplot
available for the motivated dev.

Fixes: lp:1810311
* https://bugs.launchpad.net/kicad/+bug/1810311

(cherry picked from commit c1c4a0925d)
2019-03-26 14:59:18 -07:00
John Beard 4e2e69c9cb Fix MSYS2 build breakage
wxPlatformInfo::Get() causes a linker error on Msys2.

Fix this by making common link wx explicitly, rather
than implicity via it's dependencies, which cause
wrong-order linker command lines on windows.

(cherry picked from commit aef369f4af)
2019-03-26 10:53:31 +00:00
John Beard 6f78bb6960 Add configuration of Hi-DPI canvas scaling in OpenGL
First, add automatic detection of toolkit DPI scaling options. For now, this
is, in order,

* Check the GDK_SCALE option under GTK+ (users can set this to force the scaling)
* Check the value from WX's GetContentScalingFactor(). This will start to work
  correctly from WX 3.1 and GTK+ 3.10.

Then, add a user-settable override in the main prefs panel, next to the icon
scaling. This is independent of the icon scaling options.

DPI handling is performed in a standalone class, so they can be shared between
the prefs UI and the OpenGL backend easily. Also means Cairo could use the same
interface in future.

Also adjust the OpenGL grid drawing code to use the computed scale factor,
which avoids over-thick grids in scaled environments (the user can manually
thicken the grid if wanted).

Fixes: lp:1797308
* https://bugs.launchpad.net/kicad/+bug/1797308

Cherry-pick of: 567bdd9b9 (master)
2019-03-25 15:16:18 +00:00
jean-pierre charras a00caac789 Gerbview: fix crash when reading a .gbrjob, and when a file given by the .gbrjob is not found. A incorrect gerber image was created, creating crash on exit or when enable the layer view. 2019-03-24 17:40:16 +01:00
Brian Henning 4e8f191f43 Added an include to tell the compiler where to find wxIsdigit 2019-03-24 15:38:59 +01:00
jean-pierre charras b1c5afd72f Drc dialog: make track to copper zones test optional, because it can be really very time consuming 2019-03-24 15:38:59 +01:00
jean-pierre charras aa5a2225e7 Fix incorrect detection of filled zones changes in DRC check.
Commit 6006703798 fixed a crash but broke the filled zones changes detection.
Filled zones were always seen as not up to date due to the fact the filled areas were cleared too early.

The up to date detection is also optimized: the old filled polygons are no longer stored.
Instead of, the MD5_HASH is calculated and stored before clearing the filled polygons.
2019-03-24 15:38:59 +01:00
jean-pierre charras 4c7672b581 Cvpcb: cosmetic enhancement in toolbar: add a text. 2019-03-24 15:38:59 +01:00
Jon Evans 5f9fa05e21 Fix loading of components with convert parameter set to zero
(cherry picked from commit ab74445df4)
2019-03-23 18:58:17 -04:00
Wayne Stambaugh ee92fa51bc Symbol editor: improve tooltip in symbol properties dialog.
Make the "Define as power symbol" checkbox tooltip more descriptive so
the user has a better understanding of enabling this option.

Fixes lp:1804932

https://bugs.launchpad.net/kicad/+bug/1804932

(cherry picked from commit a7c8df5666)
2019-03-20 15:58:11 -04:00
Simon Richter 63b3960120 Update/regenerate pcb_calculator_frame_base.fbp
(cherry picked from commit 4896daaae5)
2019-03-19 15:21:38 -04:00
Simon Richter e5c76ddf3e Fix line endings in pcb_calculator_frame_base.fbp
No text changes

(cherry picked from commit e286ca170d)
2019-03-19 15:21:19 -04:00
Simon Richter 4b07979008 Add a few dielectric values
- Isola FR408
   https://www.isola-group.com/wp-content/uploads/data-sheets/fr408.pdf
 - Isola 370HR
   https://www.isola-group.com/wp-content/uploads/data-sheets/370hr.pdf
 - Rogers RO4003C
   https://www.rogerscorp.com/documents/726/acm/RO4000-Laminates---Data-sheet.pdf
 - Rogers RO4350B
   (as above)

(cherry picked from commit 432e12effd)
2019-03-19 10:38:43 -04:00
Seth Hillbrand 168fa09f5f Unify and correct Autosave functions
Autosave was not working correctly, partly due to different
implementations in eeschema and pcbnew and partly due to a mistaken
refactor at some point during v5 development.  This unifies the expected
autosave prefix to _autosave- for both pcbnew and eeschema.  It also
unifies the expected suffix for the backup files to -bak.

Fixes: lp:1820433
* https://bugs.launchpad.net/kicad/+bug/1820433

(cherry picked from commit 078320e2fb)
2019-03-18 10:27:09 -07:00
Seth Hillbrand 4facd57cb7 libedit: Don't move the field below the last item
There needs to be at least one item below the one we want to move down
in order to allow the action.

Fixes: lp:1820532
* https://bugs.launchpad.net/kicad/+bug/1820532

(cherry picked from commit 0943c176a3)
2019-03-18 10:27:09 -07:00
Wayne Stambaugh e999636048 Symbol editor: fix superfluous dialog display.
Call base object TransferDataFromWindow() to prevent Validate() from
being called twice.  Validation is handled completely under the hood
so there is no need to call Validate() directly.

Fixes lp:1820301

https://bugs.launchpad.net/kicad/+bug/1820301
2019-03-18 11:46:03 -04:00
Seth Hillbrand 5bd769ea40 Remove global library from pspice simulation 2019-03-17 20:56:24 +01:00
jean-pierre charras bd693f97a1 Print on Linux: use 600 DPI instead of the default 72 DPI (noticeable in Pcbnew) 2019-03-17 20:52:42 +01:00
jean-pierre charras af0cb68c1b Eeschema: do not draw dangling symbol (circle) for PIN_NC pin types. These pins are never connected, so a dangling symbol makes no sense.
Fix also a fex minor coding style issues.
2019-03-17 20:52:42 +01:00
jean-pierre charras 761d7fd438 Demo pic_programmer: remove unused schematic library from list. 2019-03-17 08:52:00 +01:00
jean-pierre charras c537e8a892 Eeschema: shows the opened sheet info in title bar.
Fixes: lp:1819564
https://bugs.launchpad.net/kicad/+bug/1819564
2019-03-17 08:52:00 +01:00
jean-pierre charras 702e85cd96 Pcbnew: disable commit 3692c511 on non Windows platforms A zone refill display progress bar is shown when deselecting the zone after geometry changes. However, on Linux, there are some artifact between the progress bar refresh and the board view refresh: the filled areas are incorrectly shown: the insulated islands remain displayed, although they are removed from the actual filled areas list So it is disabled until a fix is found. 2019-03-17 08:52:00 +01:00
Wayne Stambaugh c93e0b6c5e Minor board editor menu fixes.
Correct menu string capitalization.

Remove duplicate mnemonic characters.

Fixes lp:1818906

https://bugs.launchpad.net/kicad/+bug/1818906
2019-03-16 10:37:35 -04:00
Wayne Stambaugh f7b4a20066 Replace isdigit() with wxIsdigit() when testing wxString characters.
This is a continuation of commit 8a03025a.  All known instances of
using isdigit() to test a character in a wxString have been replaced
by wxIsdigit().
2019-03-15 15:54:49 -04:00
Seth Hillbrand 49ac89bfed pcbnew: Don't refresh S_CURVE in bbox()
The bounding box calculation needs to be fast and is threaded in many
places in pcbnew.  We cannot invalidate items (the function is const but
this wasn't caught at compile-time for some reason) when getting the
bbox. This shouldn't be an issue as the m_BezierPoints is rebuilt each
time the curve is updated, so rebuilding during the bbox seems extra.

Fixes: lp:1819984
* https://bugs.launchpad.net/kicad/+bug/1819984

(cherry picked from commit ec24981cc8)
2019-03-14 05:49:30 -07:00
jean-pierre charras 16e62b29f9 Zone fill: display progress bar when refilling a zone after edition.
Previously, refilling a zone after edition was made silently,
thus creating not understandable but very noticeable freeze time for complex zones.

(cherry picked from commit 3692c511d0)
2019-03-14 05:49:30 -07:00
jean-pierre charras b8180b0459 PROF_COUNTER: add a helper method.
(cherry picked from commit 3fc681c1b7)
2019-03-14 05:49:30 -07:00
Seth Hillbrand 37f250b384 pcbnew: Remove fills prior to updates
Removing existing fills will prevent re-drawing invalid polygons before
they are ready.  This seems to happen on Macs more easily due to redraw
timing.

Fixes: lp:1819553
* https://bugs.launchpad.net/kicad/+bug/1819553

(cherry picked from commit 6006703798)
2019-03-11 16:29:02 -07:00
Seth Hillbrand 5685ec525b GAL: Handle negative line widths
When displaying negative line width elements, the outline of the item
should be hidden rather than displayed.

Fixes: lp:1819247
* https://bugs.launchpad.net/kicad/+bug/1819247

(cherry picked from commit c61ec8ee3b)
2019-03-11 12:38:26 -07:00
Seth Hillbrand 5be59ea8dd eeschema: Fix plot line width for negative lines
Negative width lines are used to hide the outline of shapes in eeschema.
Plot should not show these lines.

(cherry picked from commit 94fa734c61)
2019-03-11 12:38:19 -07:00
Seth Hillbrand 5855f2d909 Ensure LIB_ALIAS elements are always drawn
We add LIB_ALIAS to the VIEW rtree when choosing a new symbol or
browsing.  The actual display element may change based on the unit or
demorgan representation but there will only ever be a single one drawn.
This will set the view bbox to maximum to ensure it is always checked
for drawing.

 Related to lp:1796960
 https://bugs.launchpad.net/kicad/+bug/1796960

(cherry picked from commit d25d62295a)
2019-03-10 20:18:12 -07:00
jean-pierre charras 5424223949 Thermal reliefs: fix a corner case that wrongly removes a stub in a thermal shape.
This was due to the stub removal tests if a stub end is outside a solid area to remove it.
There is a corner case: is the stub end is exactly on a solid area outline extra segment
created by Fracture() used in calculations.

The stub removal tests are now made before fracturing.

Fixes: lp:1819317
https://bugs.launchpad.net/kicad/+bug/1819317
(cherry picked from commit b9944e2c06)
2019-03-10 11:50:33 -07:00
Seth Hillbrand de22148b44 Move env var substitution into GetAssociatedDocument
We always want the documents to have their variables replaced when
opening the associated file.

Fixes: lp:1819309
* https://bugs.launchpad.net/kicad/+bug/1819309

(cherry picked from commit 9bfce26ce7)
2019-03-10 10:44:23 -07:00
Wayne Stambaugh 73664e610b Begin version 5.1.1 development. 2019-03-08 13:11:03 -05:00
17923 changed files with 1074579 additions and 17051098 deletions
-57
View File
@@ -1,57 +0,0 @@
# minimum clang-format 10
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: true
AlignOperands: true
AlignTrailingComments: true
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakConstructorInitializersBeforeComma: false
BreakStringLiterals: true
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ BOOST_FOREACH ]
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 2
NamespaceIndentation: Inner
PointerAlignment: Left
ReflowComments: false
SortIncludes: false
SpaceAfterCStyleCast: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: true
SpacesInSquareBrackets: false
Standard: c++11
TabWidth: 4
UseTab: Never
-5
View File
@@ -1,5 +0,0 @@
# SPDX-License-Identifier: GPL-3.0-or-later
Checks: '-clang-diagnostic-*,clang-analyzer-*, bugprone-*, modernize-deprecated-headers, modernize-loop-convert, modernize-use-override, modernize-redundant-void-arg, modernize-use-emplace, modernize-use-noexcept, modernize-use-bool-literals, modernize-pass-by-value, modernize-use-equals-default, modernize-use-equals-delete, modernize-use-default-member-init, cppcoreguidelines-prefer-member-initializer, cppcoreguidelines-init-variables, cppcoreguidelines-pro-type-member-init'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
FormatStyle: 'file'
+2 -7
View File
@@ -1,9 +1,9 @@
# Custom attribute to mark source files using KiCad C++ formatting
[attr]kicad-cpp-source text=auto whitepace=tab-in-indent format.clang-format-kicad
[attr]kicad-cpp-source whitepace=tab-in-indent format.clang-format-kicad
# Custom attribute to mark KiCad's own CMake files
[attr]kicad-cmake-source text=auto whitespace=tab-in-indent
[attr]kicad-cmake-source whitespace=tab-in-indent
# Custom attribute for auto-generated sources:
# * Do not perform whitespace checking
@@ -18,7 +18,6 @@
*.cmake kicad-cmake-source
*.txt kicad-cmake-source
*.md text=auto
# Compiled bitmap sources
bitmaps_png/cpp_*/*.cpp generated
@@ -30,7 +29,3 @@ bitmaps_png/cpp_*/*.cpp generated
# Lemon grammars
common/libeval/grammar.c generated
common/libeval/grammar.h generated
# Scripts
*.sh text eol=lf
*.bat text eol=crlf
-2
View File
@@ -1,2 +0,0 @@
custom: "https://donate.kicad.org"
community_bridge: kicad
-26
View File
@@ -1,26 +0,0 @@
name: 'Redirect PRs'
on:
pull_request:
types: opened
jobs:
lockdown:
runs-on: ubuntu-latest
steps:
- uses: dessant/repo-lockdown@v2
with:
github-token: ${{ github.token }}
pr-comment: >
Thank you for offering to help improve KiCad.
This repository is a one-way mirror that can not accept pull requests.
Please submit your merge request to the official KiCad repository
at https://gitlab.com/kicad/code/kicad/-/merge_requests
While we know that _your_ PR is not spam, we mark it as such to dissuade
the Hacktoberfest PRs. Please join us over at GitLab. You can even use
your GitHub credentials to log in there without creating a new account.
skip-closed-pr-comment: true
pr-labels: 'spam'
close-pr: true
lock-pr: true
pr-lock-reason: 'spam'
+19 -43
View File
@@ -1,38 +1,41 @@
.downloads-by-cmake
.gdb_history
boost_root
/Build*
/build*
/cmake-build-*
Build*
build*
common/fp_lib_table_keywords.cpp
common/drc_rules_keywords.cpp
common/drc_rules_lexer.h
common/netlist_keywords.*
common/netlist_lexer.h
common/pcb_plot_params_lexer.h
common/drawing_sheet/drawing_sheet_reader_keywords.cpp
common/page_layout/page_layout_reader_keywords.cpp
common/lib_table_keywords.*
common/gal/opengl/shader_src.h
include/fp_lib_table_lexer.h
include/lib_table_lexer.h
include/netlist_lexer.h
include/page_layout_reader_lexer.h
eeschema/cmp_library_lexer.h
eeschema/cmp_library_keywords.*
eeschema/dialogs/dialog_bom_cfg_keywords.cpp
eeschema/dialogs/dialog_bom_cfg_lexer.h
common/template_fieldnames_keywords.cpp
common/template_fieldnames_lexer.h
eeschema/schematic_keywords.*
eeschema/dialogs/dialog_bom_help_html.h
eeschema/template_fieldnames_keywords.*
eeschema/template_fieldnames_lexer.h
pcbnew/pcb_plot_params_keywords.cpp
pcbnew/pcb_plot_params_lexer.h
pcb_calculator/attenuators/bridget_tee_formula.h
pcb_calculator/attenuators/pi_formula.h
pcb_calculator/attenuators/splitter_formula.h
pcb_calculator/attenuators/tee_formula.h
Makefile
CMakeUserPresets.json
CMakeCache.txt
.cache/
auto_renamed_to_cpp
Testing
version.h
config.h
install_manifest.txt
doxygen/out
Documentation/doxygen
Documentation/development/doxygen
*.bak
*.pyc
common/pcb_plot_params_keywords.cpp
@@ -46,17 +49,16 @@ new/sch_lib_table_keywords.cpp
new/sch_lib_table_lexer.h
new/sweet_keywords.cpp
new/sweet_lexer.h
bitmaps_png/png*
bitmaps_png/tmp
common/pcb_keywords.cpp
include/pcb_lexer.h
fp-info-cache
qa/tests/output/**
# demo project auxiliary files
# demo project auxillary files
demos/**/*-bak
demos/**/_autosave-*
demos/**/fp-info-cache
demos/**/~*.lck
# MacOS package info created by CMake
bitmap2component/Info.plist
@@ -76,9 +78,8 @@ pcbnew/Info.plist
*.png
*.kiface
*.o
*.o.*
*.a
*.a.*
*.cmake
*.orig
*.rej
*.so
@@ -88,10 +89,9 @@ pcbnew/Info.plist
*.patch
# These CMake files are wanted
!cmake/**/*.cmake
!CMakeModules/*.cmake
# Eclipse IDE
.settings/
.project
.cproject
.pydevproject
@@ -101,10 +101,6 @@ __pycache__
.vs/
.editorconfig
CMakeSettings.json
.vscode/
compile_commands.json
/vcpkg_installed
CMakePresets.json
# Sublime Text
*.sublime-*
@@ -113,27 +109,7 @@ CMakePresets.json
.kdev4/
*.kdev4
# Qt Creator
CMakeLists.txt.user
*.autosave
# Translations
*.mo
i18n_status.svg
i18n_status.csv
# Project local settings files and backups (in demos and qa tests)
*.kicad_prl
*-backups
# QA dataoutput
qa/data/**/*.csv
# Don't actually ignore any of these files, since we need them in the tree
!resources/linux/icons/hicolor/**/**/*
!resources/linux/icons-nightly/hicolor/**/**/*
!CMakeModules/**/*
!resources/bitmaps_png/png/**/*
# Junk temp files generated by MSVC for resource files
/resources/msw/RC*
-23
View File
@@ -1,23 +0,0 @@
stages:
- build
- test
- report
variables:
DEFAULT_FEDORA_IMAGE: registry.gitlab.com/kicad/kicad-ci/source_containers/master/fedora:40
default:
image:
name: $DEFAULT_FEDORA_IMAGE
entrypoint: ["/bin/sh", "-c"]
include:
- local: '/.gitlab/templates.yml'
- local: '/.gitlab/Fedora-Linux-CI.yml'
- local: '/.gitlab/Ubuntu-20.04-CI.yml'
- local: '/.gitlab/Windows-CI.yml'
- local: '/.gitlab/macOS-CI.yml'
- local: '/.gitlab/coverity.yml'
- local: '/.gitlab/linux-metadata-validate.yml'
- local: '/.gitlab/doxygen.yml'
- local: '/.gitlab/mr_formatting.yml'
-179
View File
@@ -1,179 +0,0 @@
##########################################################################
# Build KiCad on Fedora and save the results
##########################################################################
.fedora_build_linux_base:
stage: build
# Don't tag until we have separate CI for MRs
# tags:
# - kicad-fedora
image: $DEFAULT_FEDORA_IMAGE
extends: .only_code
interruptible: false
cache:
key: "cache-fedora-linux"
paths:
- ccache/
before_script:
# CCache Config
- mkdir -p ccache
- export CCACHE_BASEDIR=${PWD}
- export CCACHE_DIR=${PWD}/ccache
script:
- mkdir -p build/linux
- cd build/linux
- cmake
-G Ninja
-DCMAKE_BUILD_TYPE=QABUILD
-DKICAD_STDLIB_LIGHT_DEBUG=ON
-DKICAD_BUILD_I18N=ON
-DKICAD_TEST_XML_OUTPUT=ON
-DKICAD_BUILD_PNS_DEBUG_TOOL=ON
-DKICAD_USE_CMAKE_FINDPROTOBUF=ON
../../
- ninja 2>&1 | tee compilation_log.txt
- cd ../../
artifacts:
# Only save the artifacts that are needed for running the tests in the next stage
# and the compilation log. The entire build directory is too large to save as an
# artifact.
expire_in: 2 hrs
when: always
paths:
- build/linux/3d-viewer/
- build/linux/api/libkiapi.so*
- build/linux/common/libkicommon.so*
- build/linux/common/gal/libkigal.so*
- build/linux/eeschema/_eeschema.kiface
- build/linux/cvpcb/_cvpcb.kiface
- build/linux/kicad/kicad-cli
- build/linux/pcbnew/pcbnew.py
- build/linux/pcbnew/_pcbnew.kiface
- build/linux/pcbnew/_pcbnew.so
- build/linux/qa/
- build/linux/schemas/
- build/linux/compilation_log.txt
exclude:
- build/linux/**/*.o
- build/linux/**/*.a
# This split is to ensure we can always use our runner for our jobs
fedora_build_linux_kicad:
extends: .fedora_build_linux_base
tags:
- kicad-fedora
only:
variables:
- $CI_PROJECT_ROOT_NAMESPACE == "kicad"
fedora_build_linux_public:
extends: .fedora_build_linux_base
tags:
- saas-linux-medium-amd64
except:
variables:
- $CI_PROJECT_ROOT_NAMESPACE == "kicad"
# Upload the compilation log in an easily downloadable form
.fedora_report_build_warn:
stage: report
extends: .only_code
when: always
script:
- echo "Uploading compilation log"
- cp build/linux/compilation_log.txt compilation_log.txt
artifacts:
expire_in: 1 year
expose_as: 'Build log'
name: "build_log.txt"
paths:
- compilation_log.txt
fedora_report_build_warn_kicad:
extends: .fedora_report_build_warn
tags:
- kicad-fedora
needs:
- job: fedora_build_linux_kicad
artifacts: true
only:
variables:
- $CI_PROJECT_ROOT_NAMESPACE == "kicad"
fedora_report_build_warn_public:
extends: .fedora_report_build_warn
needs:
- job: fedora_build_linux_public
artifacts: true
except:
variables:
- $CI_PROJECT_ROOT_NAMESPACE == "kicad"
# Report on the metrics of the code
.fedora_report_metrics:
stage: report
extends: .only_code
when: always
script:
- cat build/linux/compilation_log.txt | { grep "warning:" || test $? = 1; } | awk 'END{print "number_of_fedora_warnings "NR}' > metrics.txt
- cat metrics.txt
artifacts:
reports:
metrics: metrics.txt
fedora_report_metrics_kicad:
extends: .fedora_report_metrics
tags:
- kicad-fedora
needs:
- job: fedora_build_linux_kicad
artifacts: true
only:
variables:
- $CI_PROJECT_ROOT_NAMESPACE == "kicad"
fedora_report_metrics_public:
extends: .fedora_report_metrics
needs:
- job: fedora_build_linux_public
artifacts: true
except:
variables:
- $CI_PROJECT_ROOT_NAMESPACE == "kicad"
##########################################################################
# Run the code unit tests.
##########################################################################
.fedora_qa:
image: $DEFAULT_FEDORA_IMAGE
extends:
- .unit_test
- .only_code
before_script:
- if [ "$TEST" == "cli" ] || [ "$TEST" == "python" ]; then python3 -m pip install -r qa/tests/requirements.txt; fi
- if [ "$TEST" == "cli" ]; then sudo dnf -y install gerbv; fi
parallel:
matrix:
# The name of the test without the qa_ prefix
- TEST: [python, cli, common, gerbview, pcbnew, pns_regressions, eeschema, kimath, sexpr, kicad2step, spice, api]
fedora_qa_kicad:
extends: .fedora_qa
tags:
- kicad-fedora
needs:
- job: fedora_build_linux_kicad
artifacts: true
only:
variables:
- $CI_PROJECT_ROOT_NAMESPACE == "kicad"
fedora_qa_public:
extends: .fedora_qa
needs:
- job: fedora_build_linux_public
artifacts: true
except:
variables:
- $CI_PROJECT_ROOT_NAMESPACE == "kicad"
-118
View File
@@ -1,118 +0,0 @@
##########################################################################
# Build KiCad on Ubuntu 20.04 and save the results
##########################################################################
.ubuntu20.04_build:
stage: build
tags:
- kicad-ubuntu20.04
image: registry.gitlab.com/kicad/kicad-ci/source_containers/master/ubuntu:20.04
only:
- branches@kicad/code/kicad
- tags@kicad/code/kicad
except:
- schedules
interruptible: false
cache:
key: "cache-ubuntu20.04-linux"
paths:
- ccache/
before_script:
# CCache Config
- mkdir -p ccache
- export CCACHE_BASEDIR=${PWD}
- export CCACHE_DIR=${PWD}/ccache
script:
- mkdir -p build/linux
- cd build/linux
- cmake
-G Ninja
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCMAKE_BUILD_TYPE=Release
-DKICAD_STDLIB_LIGHT_DEBUG=ON
-DKICAD_SCRIPTING_WXPYTHON=ON
-DKICAD_USE_OCC=ON
-DKICAD_BUILD_I18N=ON
-DKICAD_BUILD_PNS_DEBUG_TOOL=ON
../../
- ninja 2>&1 | tee compilation_log.txt
- cd ../../
artifacts:
# Only save the artifacts that are needed for running the tests in the next stage
# and the compilation log. The entire build directory is too large to save as an
# artifact.
expire_in: 2 hrs
when: always
paths:
- build/linux/3d-viewer/
- build/linux/pcbnew/pcbnew.py
- build/linux/pcbnew/_pcbnew.kiface
- build/linux/pcbnew/_pcbnew.so
- build/linux/qa/
- build/linux/compilation_log.txt
exclude:
- build/linux/**/*.o
- build/linux/**/*.a
# Upload the compilation log in an easily downloadable form
.ubuntu20.04_report_build_warn:
stage: report
when: always
only:
- branches@kicad/code/kicad
- tags@kicad/code/kicad
except:
- schedules
needs:
- job: ubuntu20.04_build
artifacts: true
script:
- echo "Uploading compilation log"
- cp build/linux/compilation_log.txt compilation_log.txt
artifacts:
expire_in: 1 year
expose_as: 'Build log'
name: "build_log.txt"
paths:
- compilation_log.txt
# Report on the metrics of the code
.ubuntu20.04_report_metrics:
stage: report
when: always
only:
- branches@kicad/code/kicad
- tags@kicad/code/kicad
except:
- schedules
needs:
- job: ubuntu20.04_build
artifacts: true
script:
- cat build/linux/compilation_log.txt | { grep "warning:" || test $? = 1; } | awk 'END{print "number_of_ubuntu_20.04_warnings "NR}' > metrics.txt
- cat metrics.txt
artifacts:
reports:
metrics: metrics.txt
##########################################################################
# Run the code unit tests.
##########################################################################
.ubuntu20.04_qa:
extends:
- .unit_test
needs:
- job: ubuntu20.04_build
artifacts: true
tags:
- kicad-ubuntu20.04
image: registry.gitlab.com/kicad/kicad-ci/source_containers/master/ubuntu:20.04
only:
- branches@kicad/code/kicad
- tags@kicad/code/kicad
except:
- schedules
parallel:
matrix:
# The name of the test without the qa_ prefix
- TEST: [python, common, gerbview, pcbnew, eeschema, kimath, sexpr, kicad2step, spice]
-47
View File
@@ -1,47 +0,0 @@
##########################################################################
# Build KiCad on Windows and save the results
##########################################################################
win64_build:
stage: build
tags:
- kicad-windows-ltsc2022
interruptible: false
image: registry.gitlab.com/kicad/kicad-ci/windows-build-image/ltsc2022-msvc:latest
variables:
# Switch the compressor to fastzip and reduce the compression level
FF_USE_FASTZIP: "true"
CACHE_COMPRESSION_LEVEL: "fast"
cache:
key: win64-vcpkg-$CI_COMMIT_REF_SLUG
paths:
- build\windows\vcpkg_installed
- .vcpkgCache
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_PROJECT_ROOT_NAMESPACE == "kicad"
script:
- C:\builder\build.ps1 -Env -Arch x64
- $vcpkgCache=Join-Path -Path (Get-Location) -ChildPath ".vcpkgCache";$env:VCPKG_DEFAULT_BINARY_CACHE=$vcpkgCache;New-Item -ItemType Directory -Force -Path $vcpkgCache
- mkdir -p build/windows -Force
- cd build/windows
- cmake `
-G "Ninja" `
-DCMAKE_TOOLCHAIN_FILE=C:\builder\vcpkg\scripts\buildsystems\vcpkg.cmake `
-DCMAKE_BUILD_TYPE=Debug `
-DKICAD_SCRIPTING_WXPYTHON=OFF `
-DKICAD_USE_OCC=ON `
-DKICAD_BUILD_PNS_DEBUG_TOOL=ON `
-DKICAD_USE_3DCONNEXION=ON `
-DVCPKG_BUILD_TYPE=debug `
../../
- cmake --build . 2>&1 | tee compilation_log.txt
- cd ../../
artifacts:
# Only save the artifacts that are needed for running the tests in the next stage
# and the compilation log. The entire build directory is too large to save as an
# artifact.
expire_in: 2 hrs
when: always
paths:
- build/windows/compilation_log.txt
-76
View File
@@ -1,76 +0,0 @@
# This script is responsible for configuring the coverity file from the cache
# (e.g. extracting it or updating it if needed)
.coverity_cache_prep: &coverity_cache_prep |
echo "Downloading MD5 hash of current Coverity Scan version to compare against cache"
curl --output cov-analysis-linux64.md5 https://scan.coverity.com/download/linux64 \
--form project=$COVERITY_SCAN_PROJECT_NAME \
--form token=$COVERITY_SCAN_TOKEN \
--form md5=1
echo " *cov-analysis-linux64.tgz" >> cov-analysis-linux64.md5
(md5sum --ignore-missing -c cov-analysis-linux64.md5) || (
echo "Downloading new Coverity Scan version"
curl --output cov-analysis-linux64.tgz https://scan.coverity.com/download/linux64 \
--form project=$COVERITY_SCAN_PROJECT_NAME \
--form token=$COVERITY_SCAN_TOKEN
)
echo "Extracting Coverity Scan"
mkdir coverity/
tar xzf cov-analysis-linux64.tgz --strip-components=1 -C coverity
test -d coverity/bin
# This script is responsible for tar'ing and submitting the results of the build.
# These results will be saved for 1 day if the build fails.
.coverity_submit: &coverity_submit |
echo "Creating tar file of scan results"
export COV_INT_FILENAME=cov-int-$(date +"%Y%m%d%H%M").tar.gz
tar cfz $COV_INT_FILENAME cov-int
echo "Submitting scan results"
s5cmd/s5cmd cp $COV_INT_FILENAME s3://$KICAD_CI_R2_BUCKET/coverity/
export FILE_URL="$KICAD_CI_R2_PUBLIC_BASE/coverity/$COV_INT_FILENAME"
export KICAD_VERSION=$(sed 's/[()]//g' kicad_build_version.txt)
curl https://scan.coverity.com/builds?project=$COVERITY_SCAN_PROJECT_NAME \
--form token=$COVERITY_SCAN_TOKEN \
--form email=$GITLAB_USER_EMAIL \
--form url="$FILE_URL" \
--form version="$KICAD_VERSION" \
--form description="$KICAD_VERSION / $CI_COMMIT_TITLE" 2>&1 \
| tee curl-response.txt
grep -q 'Build successfully submitted' curl-response.txt
Coverity:
tags:
- coverity
stage: build
image: registry.gitlab.com/kicad/kicad-ci/source_containers/master/fedora:40
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULED_JOB_NAME == "coverity"
cache:
key: coverity
paths:
- cov-analysis-linux64.tgz
before_script:
- export COVERITY_SCAN_PROJECT_NAME="kicad"
- test "$(git rev-parse --is-shallow-repository)" = "false" || (git fetch --unshallow)
- git fetch origin
- curl -LO https://github.com/peak/s5cmd/releases/download/v2.0.0/s5cmd_2.0.0_Linux-64bit.tar.gz
- mkdir s5cmd
- tar -xvf ./s5cmd_2.0.0_Linux-64bit.tar.gz -C s5cmd
- export AWS_ACCESS_KEY_ID=$KICAD_CI_R2_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$KICAD_CI_R2_ACCESS_KEY
- export S3_ENDPOINT_URL=$KICAD_CI_R2_ENDPOINT
script:
- *coverity_cache_prep
- cmake
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DKICAD_STDLIB_LIGHT_DEBUG=ON
-DKICAD_SCRIPTING_WXPYTHON=ON
-DKICAD_USE_CMAKE_FINDPROTOBUF=ON
- coverity/bin/cov-build --dir cov-int make -j10
- *coverity_submit
artifacts:
expire_in: 1 year
expose_as: 'Coverity log'
name: "coverity_log.txt"
paths:
- cov-int/build-log.txt
-15
View File
@@ -1,15 +0,0 @@
build_doxygen_docker:
image: docker:stable
services:
- docker:dind
stage: build
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULED_JOB_NAME == "doxygen"
tags:
- gitlab-org-docker
before_script:
- docker info
- docker login -u gitlab-ci-token -p "$CI_JOB_TOKEN" "$CI_REGISTRY"
script:
- docker build -t "${CI_REGISTRY_IMAGE}/doxygen:$CI_COMMIT_BRANCH" -f ./doxygen/doxygen.Dockerfile .
- docker push "${CI_REGISTRY_IMAGE}/doxygen:$CI_COMMIT_BRANCH"
-20
View File
@@ -1,20 +0,0 @@
<!-- --------Before Creating a New Issue-----------
* Limit report to a single issue.
* Search the issue tracker to verify the issue has not already been reported.
* Complete all instructions between `template comment markers <>.
* Keep report contents limited to the necessary information required to fix the issue.
* When creating an issue against the stable version of KiCad, make sure the latest available stable version is installed as issues may have already been resolved in later stable versions. -->
# Description
<!-- What is the current behavior and what is the expected behavior? -->
<!-- If the issue is visual/graphical, please attach screenshots of the problem. -->
<!-- Add the issue details below this line and before the "Steps to reproduce" heading. -->
# Steps to reproduce
<!-- If there are multiple steps to reproduce it or it is a visual issue, then providing a screen recording as an attachment to this report is recommended. -->
<!-- If this issue is specific to a project, please attach the necessary files to this issue. -->
<!-- Add the steps to reproduce using the numbers below -->
<!-- Add new step numbers before the "KiCad Version" heading. -->
1.
# KiCad Version
-32
View File
@@ -1,32 +0,0 @@
##########################################################################
# Run a validation of the metadata files for Linux
##########################################################################
validate_linux_metadata:
stage: test
needs: []
interruptible: false
image: $DEFAULT_FEDORA_IMAGE
# Due to bug https://github.com/hughsie/appstream-glib/issues/381, this doesn't think our description tag
# is localized even though it actually is.
allow_failure: true
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- resources/linux/**/*
- qa/resources/linux/**/*
- translation/**/*
# Only build the metadata files in this CI job
script:
- mkdir -p build/linux
- cd build/linux
- cmake
-DCMAKE_BUILD_TYPE=Debug
-DKICAD_STDLIB_LIGHT_DEBUG=ON
-DKICAD_SCRIPTING_WXPYTHON=ON
-DKICAD_BUILD_I18N=ON
../../
- make metadata
- cd ../../
- ./qa/resources/linux/verifyMetadataFiles.sh ./ ./build/linux
-29
View File
@@ -1,29 +0,0 @@
##########################################################################
# Build KiCad on Windows and save the results
##########################################################################
macos_build:
stage: build
tags:
- kicad-macos
interruptible: false
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_PROJECT_ROOT_NAMESPACE == "kicad"
script:
- mkdir -p build/macos
- cd build/macos
- cmake
-G Ninja
-DCMAKE_TOOLCHAIN_FILE=/Users/$USER/kicad-mac-builder/toolchain/kicad-mac-builder.cmake
../../
- cmake --build . 2>&1 | tee compilation_log.txt
- cd ../../
artifacts:
# Only save the artifacts that are needed for running the tests in the next stage
# and the compilation log. The entire build directory is too large to save as an
# artifact.
expire_in: 2 hrs
when: always
paths:
- build/macos/compilation_log.txt
-27
View File
@@ -1,27 +0,0 @@
##########################################################################
# Test the formatting in a merge request using clang-format
##########################################################################
# The variable CI_COMMIT_BEFORE_SHA is not available in normal merge requests
# so we must build the commit hash ourselves, see:
# https://gitlab.com/gitlab-org/gitlab/-/issues/12850
test_formatting:
stage: test
needs: []
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
allow_failure: true
before_script:
# We must manually add the KiCad remote to ensure it is named sensibly
- git remote add product https://gitlab.com/kicad/code/kicad.git ||
git remote set-url product https://gitlab.com/kicad/code/kicad.git
- git remote add source ${CI_MERGE_REQUEST_SOURCE_PROJECT_URL}.git ||
git remote set-url source ${CI_MERGE_REQUEST_SOURCE_PROJECT_URL}.git
- git fetch -n product
- git fetch -n source
# Get the SHAs of the commits
- "TARGET_HEAD_SHA=$(git rev-parse product/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME})"
- "SOURCE_HEAD_SHA=$(git rev-parse source/${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME})"
- "MERGE_BASE_SHA=$(git merge-base ${TARGET_HEAD_SHA} ${SOURCE_HEAD_SHA})"
script:
- echo "Testing formatting from commit ${MERGE_BASE_SHA}"
- ./tools/check_coding.sh --diff --ci --commit ${MERGE_BASE_SHA}
-37
View File
@@ -1,37 +0,0 @@
##########################################################################
# This will allow the job to run whenever code events trigger it.
##########################################################################
.only_code:
only:
- master
- branches
- merge_requests
- pushes
except:
- schedules
##########################################################################
# Define a template for all the unit tests, since each one is run in a separate
# job to make the display nicer.
##########################################################################
.unit_test:
stage: test
when: on_success
variables:
BOOST_TEST_LOGGER: 'JUNIT,warning,test_results.${TEST}.xml:HRF,message'
CTEST_OUTPUT_ON_FAILURE: 1
script:
- cd build/linux/qa
- ctest -R qa_${TEST}
# GitLab supports displaying the results in the GUI through JUNIT artifacts
# (https://docs.gitlab.com/ee/ci/junit_test_reports.html)
# so we upload the JUNIT results.
artifacts:
when: always
paths:
- build/linux/qa/**/*.log
- build/linux/qa/**/output/*
- build/linux/qa/**/*.xml
reports:
junit:
- build/linux/qa/**/*.xml
+331 -173
View File
@@ -2,8 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022 CERN
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -25,40 +24,55 @@
#define GLM_FORCE_RADIANS
#include <mutex>
#include <iostream>
#include <sstream>
#include <fstream>
#include <utility>
#include <iterator>
#include <wx/datetime.h>
#include <wx/dir.h>
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/stdpaths.h>
#include <boost/version.hpp>
#if BOOST_VERSION >= 106800
#include <boost/uuid/detail/sha1.hpp>
#else
#include <boost/uuid/sha1.hpp>
#endif
#include <glm/glm.hpp>
#include <glm/ext.hpp>
#include "common.h"
#include "3d_cache.h"
#include "3d_info.h"
#include "3d_plugin_manager.h"
#include "sg/scenegraph.h"
#include "filename_resolver.h"
#include "3d_plugin_manager.h"
#include "plugins/3dapi/ifsg_api.h"
#include <advanced_config.h>
#include <common.h> // For ExpandEnvVarSubstitutions
#include <filename_resolver.h>
#include <mmh3_hash.h>
#include <paths.h>
#include <pgm_base.h>
#include <project.h>
#include <settings/common_settings.h>
#include <settings/settings_manager.h>
#include <wx_filename.h>
#define MASK_3D_CACHE "3D_CACHE"
static std::mutex mutex3D_cache;
static wxCriticalSection lock3D_cache;
static bool isSHA1Same( const unsigned char* shaA, const unsigned char* shaB )
{
for( int i = 0; i < 20; ++i )
if( shaA[i] != shaB[i] )
return false;
return true;
}
static bool checkTag( const char* aTag, void* aPluginMgrPtr )
{
if( nullptr == aTag || nullptr == aPluginMgrPtr )
if( NULL == aTag || NULL == aPluginMgrPtr )
return false;
S3D_PLUGIN_MANAGER *pp = (S3D_PLUGIN_MANAGER*) aPluginMgrPtr;
@@ -67,57 +81,101 @@ static bool checkTag( const char* aTag, void* aPluginMgrPtr )
}
static const wxString sha1ToWXString( const unsigned char* aSHA1Sum )
{
unsigned char uc;
unsigned char tmp;
char sha1[41];
int j = 0;
for( int i = 0; i < 20; ++i )
{
uc = aSHA1Sum[i];
tmp = uc / 16;
if( tmp > 9 )
tmp += 87;
else
tmp += 48;
sha1[j++] = tmp;
tmp = uc % 16;
if( tmp > 9 )
tmp += 87;
else
tmp += 48;
sha1[j++] = tmp;
}
sha1[j] = 0;
return wxString::FromUTF8Unchecked( sha1 );
}
class S3D_CACHE_ENTRY
{
public:
S3D_CACHE_ENTRY();
~S3D_CACHE_ENTRY();
void SetHash( const HASH_128& aHash );
const wxString GetCacheBaseName();
wxDateTime modTime; // file modification time
HASH_128 m_hash;
std::string pluginInfo; // PluginName:Version string
SCENEGRAPH* sceneData;
S3DMODEL* renderData;
private:
// prohibit assignment and default copy constructor
S3D_CACHE_ENTRY( const S3D_CACHE_ENTRY& source );
S3D_CACHE_ENTRY& operator=( const S3D_CACHE_ENTRY& source );
wxString m_CacheBaseName; // base name of cache file
wxString m_CacheBaseName; // base name of cache file (a SHA1 digest)
public:
S3D_CACHE_ENTRY();
~S3D_CACHE_ENTRY();
void SetSHA1( const unsigned char* aSHA1Sum );
const wxString GetCacheBaseName( void );
wxDateTime modTime; // file modification time
unsigned char sha1sum[20];
std::string pluginInfo; // PluginName:Version string
SCENEGRAPH* sceneData;
S3DMODEL* renderData;
};
S3D_CACHE_ENTRY::S3D_CACHE_ENTRY()
{
sceneData = nullptr;
renderData = nullptr;
m_hash.Clear();
sceneData = NULL;
renderData = NULL;
memset( sha1sum, 0, 20 );
}
S3D_CACHE_ENTRY::~S3D_CACHE_ENTRY()
{
delete sceneData;
if( NULL != sceneData )
delete sceneData;
if( nullptr != renderData )
if( NULL != renderData )
S3D::Destroy3DModel( &renderData );
}
void S3D_CACHE_ENTRY::SetHash( const HASH_128& aHash )
void S3D_CACHE_ENTRY::SetSHA1( const unsigned char* aSHA1Sum )
{
m_hash = aHash;
if( NULL == aSHA1Sum )
{
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * [BUG] NULL passed for aSHA1Sum",
__FILE__, __FUNCTION__, __LINE__ );
return;
}
memcpy( sha1sum, aSHA1Sum, 20 );
return;
}
const wxString S3D_CACHE_ENTRY::GetCacheBaseName()
const wxString S3D_CACHE_ENTRY::GetCacheBaseName( void )
{
if( m_CacheBaseName.empty() )
m_CacheBaseName = m_hash.ToString();
m_CacheBaseName = sha1ToWXString( sha1sum );
return m_CacheBaseName;
}
@@ -125,9 +183,11 @@ const wxString S3D_CACHE_ENTRY::GetCacheBaseName()
S3D_CACHE::S3D_CACHE()
{
m_DirtyCache = false;
m_FNResolver = new FILENAME_RESOLVER;
m_project = nullptr;
m_Plugins = new S3D_PLUGIN_MANAGER;
return;
}
@@ -135,30 +195,33 @@ S3D_CACHE::~S3D_CACHE()
{
FlushCache();
delete m_FNResolver;
delete m_Plugins;
if( m_FNResolver )
delete m_FNResolver;
if( m_Plugins )
delete m_Plugins;
return;
}
SCENEGRAPH* S3D_CACHE::load( const wxString& aModelFile, const wxString& aBasePath,
S3D_CACHE_ENTRY** aCachePtr, const EMBEDDED_FILES* aEmbeddedFiles )
SCENEGRAPH* S3D_CACHE::load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCachePtr )
{
if( aCachePtr )
*aCachePtr = nullptr;
*aCachePtr = NULL;
wxString full3Dpath = m_FNResolver->ResolvePath( aModelFile, aBasePath, aEmbeddedFiles );
wxString full3Dpath = m_FNResolver->ResolvePath( aModelFile );
if( full3Dpath.empty() )
{
// the model cannot be found; we cannot proceed
wxLogTrace( MASK_3D_CACHE, wxT( "%s:%s:%d\n * [3D model] could not find model '%s'\n" ),
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * [3D model] could not find model '%s'\n",
__FILE__, __FUNCTION__, __LINE__, aModelFile );
return nullptr;
return NULL;
}
// check cache if file is already loaded
std::lock_guard<std::mutex> lock( mutex3D_cache );
wxCriticalSectionLocker lock( lock3D_cache );
std::map< wxString, S3D_CACHE_ENTRY*, rsort_wxString >::iterator mi;
mi = m_CacheMap.find( full3Dpath );
@@ -168,39 +231,38 @@ SCENEGRAPH* S3D_CACHE::load( const wxString& aModelFile, const wxString& aBasePa
if( fname.FileExists() ) // Only check if file exists. If not, it will
{ // use the same model in cache.
bool reload = ADVANCED_CFG::GetCfg().m_Skip3DModelMemoryCache;
bool reload = false;
wxDateTime fmdate = fname.GetModificationTime();
if( fmdate != mi->second->modTime )
{
HASH_128 hashSum;
getHash( full3Dpath, hashSum );
unsigned char hashSum[20];
getSHA1( full3Dpath, hashSum );
mi->second->modTime = fmdate;
if( hashSum != mi->second->m_hash )
if( !isSHA1Same( hashSum, mi->second->sha1sum ) )
{
mi->second->SetHash( hashSum );
mi->second->SetSHA1( hashSum );
reload = true;
}
}
if( reload )
{
if( nullptr != mi->second->sceneData )
if( NULL != mi->second->sceneData )
{
S3D::DestroyNode( mi->second->sceneData );
mi->second->sceneData = nullptr;
mi->second->sceneData = NULL;
}
if( nullptr != mi->second->renderData )
if( NULL != mi->second->renderData )
S3D::Destroy3DModel( &mi->second->renderData );
mi->second->sceneData = m_Plugins->Load3DModel( full3Dpath,
mi->second->pluginInfo );
mi->second->sceneData = m_Plugins->Load3DModel( full3Dpath, mi->second->pluginInfo );
}
}
if( nullptr != aCachePtr )
if( NULL != aCachePtr )
*aCachePtr = mi->second;
return mi->second->sceneData;
@@ -211,34 +273,33 @@ SCENEGRAPH* S3D_CACHE::load( const wxString& aModelFile, const wxString& aBasePa
}
SCENEGRAPH* S3D_CACHE::Load( const wxString& aModelFile, const wxString& aBasePath,
const EMBEDDED_FILES* aEmbeddedFiles )
SCENEGRAPH* S3D_CACHE::Load( const wxString& aModelFile )
{
return load( aModelFile, aBasePath, nullptr, aEmbeddedFiles );
return load( aModelFile );
}
SCENEGRAPH* S3D_CACHE::checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr )
{
if( aCachePtr )
*aCachePtr = nullptr;
*aCachePtr = NULL;
HASH_128 hashSum;
S3D_CACHE_ENTRY* ep = new S3D_CACHE_ENTRY;
m_CacheList.push_back( ep );
wxFileName fname( aFileName );
ep->modTime = fname.GetModificationTime();
unsigned char sha1sum[20];
if( !getHash( aFileName, hashSum ) || m_CacheDir.empty() )
if( !getSHA1( aFileName, sha1sum ) || m_CacheDir.empty() )
{
// just in case we can't get a hash digest (for example, on access issues)
// or we do not have a configured cache file directory, we create an
// entry to prevent further attempts at loading the file
S3D_CACHE_ENTRY* ep = new S3D_CACHE_ENTRY;
m_CacheList.push_back( ep );
wxFileName fname( aFileName );
ep->modTime = fname.GetModificationTime();
if( m_CacheMap.emplace( aFileName, ep ).second == false )
if( m_CacheMap.insert( std::pair< wxString, S3D_CACHE_ENTRY* >
( aFileName, ep ) ).second == false )
{
wxLogTrace( MASK_3D_CACHE,
wxT( "%s:%s:%d\n * [BUG] duplicate entry in map file; key = '%s'" ),
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * [BUG] duplicate entry in map file; key = '%s'",
__FILE__, __FUNCTION__, __LINE__, aFileName );
m_CacheList.pop_back();
@@ -248,71 +309,100 @@ SCENEGRAPH* S3D_CACHE::checkCache( const wxString& aFileName, S3D_CACHE_ENTRY**
{
if( aCachePtr )
*aCachePtr = ep;
}
return nullptr;
return NULL;
}
if( m_CacheMap.emplace( aFileName, ep ).second == false )
S3D_CACHE_ENTRY* ep = new S3D_CACHE_ENTRY;
m_CacheList.push_back( ep );
wxFileName fname( aFileName );
ep->modTime = fname.GetModificationTime();
if( m_CacheMap.insert( std::pair< wxString, S3D_CACHE_ENTRY* >
( aFileName, ep ) ).second == false )
{
wxLogTrace( MASK_3D_CACHE,
wxT( "%s:%s:%d\n * [BUG] duplicate entry in map file; key = '%s'" ),
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * [BUG] duplicate entry in map file; key = '%s'",
__FILE__, __FUNCTION__, __LINE__, aFileName );
m_CacheList.pop_back();
delete ep;
return nullptr;
return NULL;
}
if( aCachePtr )
*aCachePtr = ep;
ep->SetHash( hashSum );
ep->SetSHA1( sha1sum );
wxString bname = ep->GetCacheBaseName();
wxString cachename = m_CacheDir + bname + wxT( ".3dc" );
if( !ADVANCED_CFG::GetCfg().m_Skip3DModelFileCache && wxFileName::FileExists( cachename )
&& loadCacheData( ep ) )
if( wxFileName::FileExists( cachename ) && loadCacheData( ep ) )
return ep->sceneData;
ep->sceneData = m_Plugins->Load3DModel( aFileName, ep->pluginInfo );
if( !ADVANCED_CFG::GetCfg().m_Skip3DModelFileCache && nullptr != ep->sceneData )
if( NULL != ep->sceneData )
saveCacheData( ep );
return ep->sceneData;
}
bool S3D_CACHE::getHash( const wxString& aFileName, HASH_128& aHash )
bool S3D_CACHE::getSHA1( const wxString& aFileName, unsigned char* aSHA1Sum )
{
if( aFileName.empty() )
{
wxLogTrace( MASK_3D_CACHE, wxT( "%s:%s:%d\n * [BUG] empty filename" ),
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * [BUG] empty filename",
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
#ifdef _WIN32
FILE* fp = _wfopen( aFileName.wc_str(), L"rb" );
#else
FILE* fp = fopen( aFileName.ToUTF8(), "rb" );
#endif
if( NULL == aSHA1Sum )
{
wxLogTrace( MASK_3D_CACHE, "%s\n * [BUG] NULL pointer passed for aMD5Sum",
__FILE__, __FUNCTION__, __LINE__ );
if( nullptr == fp )
return false;
}
#ifdef _WIN32
FILE* fp = _wfopen( aFileName.wc_str(), L"rb" );
#else
FILE* fp = fopen( aFileName.ToUTF8(), "rb" );
#endif
if( NULL == fp )
return false;
MMH3_HASH dblock( 0xA1B2C3D4 );
std::vector<char> block( 4096 );
boost::uuids::detail::sha1 dblock;
unsigned char block[4096];
size_t bsize = 0;
while( ( bsize = fread( block.data(), 1, 4096, fp ) ) > 0 )
dblock.add( block );
while( ( bsize = fread( &block, 1, 4096, fp ) ) > 0 )
dblock.process_bytes( block, bsize );
fclose( fp );
aHash = dblock.digest();
unsigned int digest[5];
dblock.get_digest( digest );
// ensure MSB order
for( int i = 0; i < 5; ++i )
{
int idx = i << 2;
unsigned int tmp = digest[i];
aSHA1Sum[idx+3] = tmp & 0xff;
tmp >>= 8;
aSHA1Sum[idx+2] = tmp & 0xff;
tmp >>= 8;
aSHA1Sum[idx+1] = tmp & 0xff;
tmp >>= 8;
aSHA1Sum[idx] = tmp & 0xff;
}
return true;
}
@@ -324,7 +414,7 @@ bool S3D_CACHE::loadCacheData( S3D_CACHE_ENTRY* aCacheItem )
if( bname.empty() )
{
wxLogTrace( MASK_3D_CACHE,
wxT( " * [3D model] cannot load cached model; no file hash available" ) );
" * [3D model] cannot load cached model; no file hash available" );
return false;
}
@@ -332,7 +422,7 @@ bool S3D_CACHE::loadCacheData( S3D_CACHE_ENTRY* aCacheItem )
if( m_CacheDir.empty() )
{
wxLogTrace( MASK_3D_CACHE,
wxT( " * [3D model] cannot load cached model; config directory unknown" ) );
" * [3D model] cannot load cached model; config directory unknown" );
return false;
}
@@ -341,16 +431,17 @@ bool S3D_CACHE::loadCacheData( S3D_CACHE_ENTRY* aCacheItem )
if( !wxFileName::FileExists( fname ) )
{
wxLogTrace( MASK_3D_CACHE, wxT( " * [3D model] cannot open file '%s'" ), fname.GetData() );
wxString errmsg = "cannot open file";
wxLogTrace( MASK_3D_CACHE, " * [3D model] %s '%s'", errmsg.GetData(), fname.GetData() );
return false;
}
if( nullptr != aCacheItem->sceneData )
if( NULL != aCacheItem->sceneData )
S3D::DestroyNode( (SGNODE*) aCacheItem->sceneData );
aCacheItem->sceneData = (SCENEGRAPH*)S3D::ReadCache( fname.ToUTF8(), m_Plugins, checkTag );
if( nullptr == aCacheItem->sceneData )
if( NULL == aCacheItem->sceneData )
return false;
return true;
@@ -359,17 +450,17 @@ bool S3D_CACHE::loadCacheData( S3D_CACHE_ENTRY* aCacheItem )
bool S3D_CACHE::saveCacheData( S3D_CACHE_ENTRY* aCacheItem )
{
if( nullptr == aCacheItem )
if( NULL == aCacheItem )
{
wxLogTrace( MASK_3D_CACHE, wxT( "%s:%s:%d\n * NULL passed for aCacheItem" ),
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * NULL passed for aCacheItem",
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
if( nullptr == aCacheItem->sceneData )
if( NULL == aCacheItem->sceneData )
{
wxLogTrace( MASK_3D_CACHE, wxT( "%s:%s:%d\n * aCacheItem has no valid scene data" ),
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * aCacheItem has no valid scene data",
__FILE__, __FUNCTION__, __LINE__ );
return false;
@@ -380,7 +471,7 @@ bool S3D_CACHE::saveCacheData( S3D_CACHE_ENTRY* aCacheItem )
if( bname.empty() )
{
wxLogTrace( MASK_3D_CACHE,
wxT( " * [3D model] cannot load cached model; no file hash available" ) );
" * [3D model] cannot load cached model; no file hash available" );
return false;
}
@@ -388,7 +479,7 @@ bool S3D_CACHE::saveCacheData( S3D_CACHE_ENTRY* aCacheItem )
if( m_CacheDir.empty() )
{
wxLogTrace( MASK_3D_CACHE,
wxT( " * [3D model] cannot load cached model; config directory unknown" ) );
" * [3D model] cannot load cached model; config directory unknown" );
return false;
}
@@ -399,15 +490,15 @@ bool S3D_CACHE::saveCacheData( S3D_CACHE_ENTRY* aCacheItem )
{
if( !wxFileName::FileExists( fname ) )
{
wxLogTrace( MASK_3D_CACHE,
wxT( " * [3D model] path exists but is not a regular file '%s'" ), fname );
wxLogTrace( MASK_3D_CACHE, " * [3D model] path exists but is not a regular file '%s'",
fname );
return false;
}
}
return S3D::WriteCache( fname.ToUTF8(), true, (SGNODE*)aCacheItem->sceneData,
aCacheItem->pluginInfo.c_str() );
aCacheItem->pluginInfo.c_str() );
}
@@ -416,9 +507,14 @@ bool S3D_CACHE::Set3DConfigDir( const wxString& aConfigDir )
if( !m_ConfigDir.empty() )
return false;
wxFileName cfgdir( ExpandEnvVarSubstitutions( aConfigDir, m_project ), wxEmptyString );
wxFileName cfgdir;
cfgdir.Normalize( FN_NORMALIZE_FLAGS );
if( aConfigDir.StartsWith( "${" ) || aConfigDir.StartsWith( "$(" ) )
cfgdir.Assign( ExpandEnvVarSubstitutions( aConfigDir ), "" );
else
cfgdir.Assign( aConfigDir, "" );
cfgdir.Normalize();
if( !cfgdir.DirExists() )
{
@@ -427,7 +523,7 @@ bool S3D_CACHE::Set3DConfigDir( const wxString& aConfigDir )
if( !cfgdir.DirExists() )
{
wxLogTrace( MASK_3D_CACHE,
wxT( "%s:%s:%d\n * failed to create 3D configuration directory '%s'" ),
"%s:%s:%d\n * failed to create 3D configuration directory '%s'",
__FILE__, __FUNCTION__, __LINE__, cfgdir.GetPath() );
return false;
@@ -440,8 +536,8 @@ bool S3D_CACHE::Set3DConfigDir( const wxString& aConfigDir )
if( !m_FNResolver->Set3DConfigDir( m_ConfigDir ) )
{
wxLogTrace( MASK_3D_CACHE,
wxT( "%s:%s:%d\n * could not set 3D Config Directory on filename resolver\n"
" * config directory: '%s'" ),
"%s:%s:%d\n * could not set 3D Config Directory on filename resolver\n"
" * config directory: '%s'",
__FILE__, __FUNCTION__, __LINE__, m_ConfigDir );
}
@@ -452,36 +548,104 @@ bool S3D_CACHE::Set3DConfigDir( const wxString& aConfigDir )
// 1. OSX: ~/Library/Caches/kicad/3d/
// 2. Linux: ${XDG_CACHE_HOME}/kicad/3d ~/.cache/kicad/3d/
// 3. MSWin: AppData\Local\kicad\3d
wxFileName cacheDir;
cacheDir.AssignDir( PATHS::GetUserCachePath() );
cacheDir.AppendDir( wxT( "3d" ) );
wxString cacheDir;
if( !cacheDir.DirExists() )
#if defined(_WIN32)
wxStandardPaths::Get().UseAppInfo( wxStandardPaths::AppInfo_None );
cacheDir = wxStandardPaths::Get().GetUserLocalDataDir();
cacheDir.append( "\\kicad\\3d" );
#elif defined(__APPLE)
cacheDir = "${HOME}/Library/Caches/kicad/3d";
#else // assume Linux
cacheDir = ExpandEnvVarSubstitutions( "${XDG_CACHE_HOME}" );
if( cacheDir.empty() || cacheDir == "${XDG_CACHE_HOME}" )
cacheDir = "${HOME}/.cache";
cacheDir.append( "/kicad/3d" );
#endif
cacheDir = ExpandEnvVarSubstitutions( cacheDir );
cfgdir.Assign( cacheDir, "" );
if( !cfgdir.DirExists() )
{
cacheDir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
cfgdir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
if( !cacheDir.DirExists() )
if( !cfgdir.DirExists() )
{
wxLogTrace( MASK_3D_CACHE,
wxT( "%s:%s:%d\n * failed to create 3D cache directory '%s'" ),
__FILE__, __FUNCTION__, __LINE__, cacheDir.GetPath() );
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * failed to create 3D cache directory '%s'",
__FILE__, __FUNCTION__, __LINE__, cfgdir.GetPath() );
return false;
}
}
m_CacheDir = cacheDir.GetPathWithSep();
m_CacheDir = cfgdir.GetPathWithSep();
return true;
}
bool S3D_CACHE::SetProject( PROJECT* aProject )
wxString S3D_CACHE::Get3DConfigDir( bool createDefault )
{
m_project = aProject;
if( !m_ConfigDir.empty() || !createDefault )
return m_ConfigDir;
// note: duplicated from common/common.cpp GetKicadConfigPath() to avoid
// code coupling; ideally the instantiating code should call
// Set3DConfigDir() to set the directory rather than relying on this
// directory remaining the same in future KiCad releases.
wxFileName cfgpath;
// From the wxWidgets wxStandardPaths::GetUserConfigDir() help:
// Unix: ~ (the home directory)
// Windows: "C:\Documents and Settings\username\Application Data"
// Mac: ~/Library/Preferences
cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
#if !defined( __WINDOWS__ ) && !defined( __WXMAC__ )
wxString envstr = ExpandEnvVarSubstitutions( "${XDG_CONFIG_HOME}" );
if( envstr.IsEmpty() || envstr == "${XDG_CONFIG_HOME}" )
{
// XDG_CONFIG_HOME is not set, so use the fallback
cfgpath.AppendDir( wxT( ".config" ) );
}
else
{
// Override the assignment above with XDG_CONFIG_HOME
cfgpath.AssignDir( envstr );
}
#endif
cfgpath.AppendDir( wxT( "kicad" ) );
cfgpath.AppendDir( wxT( "3d" ) );
if( !cfgpath.DirExists() )
{
cfgpath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
}
if( !cfgpath.DirExists() )
{
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * failed to create 3D configuration directory '%s'",
__FILE__, __FUNCTION__, __LINE__, cfgpath.GetPath() );
return wxT( "" );
}
if( Set3DConfigDir( cfgpath.GetPath() ) )
return m_ConfigDir;
return wxEmptyString;
}
bool S3D_CACHE::SetProjectDir( const wxString& aProjDir )
{
bool hasChanged = false;
if( m_FNResolver->SetProject( aProject, &hasChanged ) && hasChanged )
if( m_FNResolver->SetProjectDir( aProjDir, &hasChanged ) && hasChanged )
{
m_CacheMap.clear();
@@ -506,16 +670,23 @@ bool S3D_CACHE::SetProject( PROJECT* aProject )
void S3D_CACHE::SetProgramBase( PGM_BASE* aBase )
{
m_FNResolver->SetProgramBase( aBase );
return;
}
FILENAME_RESOLVER* S3D_CACHE::GetResolver() noexcept
wxString S3D_CACHE::GetProjectDir( void )
{
return m_FNResolver->GetProjectDir();
}
FILENAME_RESOLVER* S3D_CACHE::GetResolver( void )
{
return m_FNResolver;
}
std::list< wxString > const* S3D_CACHE::GetFileFilters() const
std::list< wxString > const* S3D_CACHE::GetFileFilters( void ) const
{
return m_Plugins->GetFileFilters();
}
@@ -537,32 +708,35 @@ void S3D_CACHE::FlushCache( bool closePlugins )
if( closePlugins )
ClosePlugins();
return;
}
void S3D_CACHE::ClosePlugins()
void S3D_CACHE::ClosePlugins( void )
{
if( m_Plugins )
if( NULL != m_Plugins )
m_Plugins->ClosePlugins();
return;
}
S3DMODEL* S3D_CACHE::GetModel( const wxString& aModelFileName, const wxString& aBasePath,
const EMBEDDED_FILES* aEmbeddedFiles )
S3DMODEL* S3D_CACHE::GetModel( const wxString& aModelFileName )
{
S3D_CACHE_ENTRY* cp = nullptr;
SCENEGRAPH* sp = load( aModelFileName, aBasePath, &cp, aEmbeddedFiles );
S3D_CACHE_ENTRY* cp = NULL;
SCENEGRAPH* sp = load( aModelFileName, &cp );
if( !sp )
return nullptr;
return NULL;
if( !cp )
{
wxLogTrace( MASK_3D_CACHE,
wxT( "%s:%s:%d\n * [BUG] model loaded with no associated S3D_CACHE_ENTRY" ),
"%s:%s:%d\n * [BUG] model loaded with no associated S3D_CACHE_ENTRY",
__FILE__, __FUNCTION__, __LINE__ );
return nullptr;
return NULL;
}
if( cp->renderData )
@@ -574,43 +748,27 @@ S3DMODEL* S3D_CACHE::GetModel( const wxString& aModelFileName, const wxString& a
return mp;
}
void S3D_CACHE::CleanCacheDir( int aNumDaysOld )
wxString S3D_CACHE::GetModelHash( const wxString& aModelFileName )
{
wxDir dir;
wxString fileSpec = wxT( "*.3dc" );
wxArrayString fileList; // Holds list of ".3dc" files found in cache directory
size_t numFilesFound = 0;
wxString full3Dpath = m_FNResolver->ResolvePath( aModelFileName );
wxFileName thisFile;
wxDateTime lastAccess, thresholdDate;
wxDateSpan durationInDays;
if( full3Dpath.empty() || !wxFileName::FileExists( full3Dpath ) )
return wxEmptyString;
// Calc the threshold date above which we delete cache files
durationInDays.SetDays( aNumDaysOld );
thresholdDate = wxDateTime::Now() - durationInDays;
// check cache if file is already loaded
std::map< wxString, S3D_CACHE_ENTRY*, rsort_wxString >::iterator mi;
mi = m_CacheMap.find( full3Dpath );
// If the cache directory can be found and opened, then we'll try and clean it up
if( dir.Open( m_CacheDir ) )
{
thisFile.SetPath( m_CacheDir ); // Set the base path to the cache folder
if( mi != m_CacheMap.end() )
return mi->second->GetCacheBaseName();
// Get a list of all the ".3dc" files in the cache directory
numFilesFound = dir.GetAllFiles( m_CacheDir, &fileList, fileSpec );
// a cache item does not exist; search the Filename->Cachename map
S3D_CACHE_ENTRY* cp = NULL;
checkCache( full3Dpath, &cp );
for( unsigned int i = 0; i < numFilesFound; i++ )
{
// Completes path to specific file so we can get its "last access" date
thisFile.SetFullName( fileList[i] );
if( NULL != cp )
return cp->GetCacheBaseName();
// Only get "last access" time to compare against. Don't need the other 2 timestamps.
if( thisFile.GetTimes( &lastAccess, nullptr, nullptr ) )
{
if( lastAccess.IsEarlierThan( thresholdDate ) )
{
// This file is older than the threshold so delete it
wxRemoveFile( thisFile.GetFullPath() );
}
}
}
}
return wxEmptyString;
}
+140 -128
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,146 +23,79 @@
/**
* @file 3d_cache.h
* defines the display data cache manager for 3D models
*/
#ifndef CACHE_3D_H
#define CACHE_3D_H
#include "3d_info.h"
#include <core/typeinfo.h>
#include "string_utils.h"
#include <hash_128.h>
#include <list>
#include <map>
#include "plugins/3dapi/c3dmodel.h"
#include <project.h>
#include <wx/string.h>
#include "kicad_string.h"
#include "filename_resolver.h"
#include "3d_info.h"
#include "plugins/3dapi/c3dmodel.h"
class EMBEDDED_FILES;
class PGM_BASE;
class S3D_CACHE;
class S3D_CACHE_ENTRY;
class SCENEGRAPH;
class FILENAME_RESOLVER;
class S3D_PLUGIN_MANAGER;
/**
* Cache for storing the 3D shapes. This cache is able to be stored as a project
* element (since it inherits from PROJECT::_ELEM).
*/
class S3D_CACHE : public PROJECT::_ELEM
class S3D_CACHE
{
public:
S3D_CACHE();
virtual ~S3D_CACHE();
PROJECT::ELEM ProjectElementType() noexcept override
{
return PROJECT::ELEM::S3DCACHE;
}
/**
* Set the configuration directory to be used by the model manager for storing 3D
* model manager configuration data and the model cache.
*
* The config directory may only be set once in the lifetime of the object.
*
* @param aConfigDir is the configuration directory to use for 3D model manager data
* @return true on success
*/
bool Set3DConfigDir( const wxString& aConfigDir );
/**
* Set the current project's working directory; this affects the model search path.
*/
bool SetProject( PROJECT* aProject );
/**
* Set the filename resolver's pointer to the application's PGM_BASE instance.
*
* The pointer is used to extract the local environment variables.
*/
void SetProgramBase( PGM_BASE* aBase );
/**
* Attempt to load the scene data for a model.
*
* It will consult the internal cache list and load from cache if possible before invoking
* the load() function of the available plugins. The model may fail to load if, for example,
* the plugin does not support rendering of the 3D model.
*
* @param aModelFile is the partial or full path to the model to be loaded.
* @param aBasePath is the path to search for any relative files
* @param aEmbeddedFiles is a pointer to the embedded files list.
* @return true if the model was successfully loaded, otherwise false.
*/
SCENEGRAPH* Load( const wxString& aModelFile, const wxString& aBasePath,
const EMBEDDED_FILES* aEmbeddedFiles );
FILENAME_RESOLVER* GetResolver() noexcept;
/**
* Return the list of file filters retrieved from the plugins.
*
* This will contain at least the default "All Files (*.*)|*.*"
*
* @return a pointer to the filter list.
*/
std::list< wxString > const* GetFileFilters() const;
/**
* Free all data in the cache and by default closes all plugins.
*/
void FlushCache( bool closePlugins = true );
/**
* Unload plugins to free memory.
*/
void ClosePlugins();
/**
* Attempt to load the scene data for a model and to translate it into an S3D_MODEL
* structure for display by a renderer.
*
* @param aModelFileName is the full path to the model to be loaded.
* @param aBasePath is the path to search for any relative files.
* @param aEmbeddedFiles is a pointer to the embedded files list.
* @return is a pointer to the render data or NULL if not available.
*/
S3DMODEL* GetModel( const wxString& aModelFileName, const wxString& aBasePath,
const EMBEDDED_FILES* aEmbeddedFiles );
/**
* Delete up old cache files in cache directory.
*
* Deletes ".3dc" files in the cache directory that are older than \a aNumDaysOld.
*
* @param aNumDaysOld is age threshold to delete ".3dc" cache files.
*/
void CleanCacheDir( int aNumDaysOld );
private:
/**
* Find or create cache entry for file name
/// cache entries
std::list< S3D_CACHE_ENTRY* > m_CacheList;
/// mapping of file names to cache names and data
std::map< wxString, S3D_CACHE_ENTRY*, rsort_wxString > m_CacheMap;
/// object to resolve file names
FILENAME_RESOLVER* m_FNResolver;
/// plugin manager
S3D_PLUGIN_MANAGER* m_Plugins;
/// set true if the cache needs to be updated
bool m_DirtyCache;
/// 3D cache directory
wxString m_CacheDir;
/// base configuration path for 3D items
wxString m_ConfigDir;
/// current KiCad project dir
wxString m_ProjDir;
/** Find or create cache entry for file name
*
* Searches the cache list for the given filename and retrieves the cache data; a cache
* entry is created if one does not already exist.
* Searches the cache list for the given filename and retrieves
* the cache data; a cache entry is created if one does not
* already exist.
*
* @param aFileName is the file name (full or partial path).
* @param aCachePtr is an optional return address for cache entry pointer.
* @return SCENEGRAPH object associated with file name or NULL on error.
* @param[in] aFileName file name (full or partial path)
* @param[out] aCachePtr optional return address for cache entry pointer
* @return SCENEGRAPH object associated with file name
* @retval NULL on error
*/
SCENEGRAPH* checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr = nullptr );
SCENEGRAPH* checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr = NULL );
/**
* Calculate the SHA1 hash of the given file.
* Function getSHA1
* calculates the SHA1 hash of the given file
*
* @param aFileName file name (full path).
* @param aHash a 128 bit hash to hold the hash.
* @return true on success, otherwise false.
* @param[in] aFileName file name (full path)
* @param[out] aSHA1Sum a 20 byte character array to hold the SHA1 hash
* @retval true success
* @retval false failure
*/
bool getHash( const wxString& aFileName, HASH_128& aHash );
bool getSHA1( const wxString& aFileName, unsigned char* aSHA1Sum );
// load scene data from a cache file
bool loadCacheData( S3D_CACHE_ENTRY* aCacheItem );
@@ -172,23 +104,103 @@ private:
bool saveCacheData( S3D_CACHE_ENTRY* aCacheItem );
// the real load function (can supply a cache entry pointer to member functions)
SCENEGRAPH* load( const wxString& aModelFile, const wxString& aBasePath,
S3D_CACHE_ENTRY** aCachePtr = nullptr,
const EMBEDDED_FILES* aEmbeddedFiles = nullptr );
SCENEGRAPH* load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCachePtr = NULL );
/// Cache entries.
std::list< S3D_CACHE_ENTRY* > m_CacheList;
public:
S3D_CACHE();
virtual ~S3D_CACHE();
/// Mapping of file names to cache names and data.
std::map< wxString, S3D_CACHE_ENTRY*, rsort_wxString > m_CacheMap;
/**
* Function Set3DConfigDir
* Sets the configuration directory to be used by the
* model manager for storing 3D model manager configuration
* data and the model cache. The config directory may only be
* set once in the lifetime of the object.
*
* @param aConfigDir is the configuration directory to use
* for 3D model manager data
* @return true on success
*/
bool Set3DConfigDir( const wxString& aConfigDir );
FILENAME_RESOLVER* m_FNResolver;
/**
* Function Get3DConfigDir
* returns the current 3D configuration directory on
* success, otherwise it returns wxEmptyString. If the
* directory was not previously set via Set3DConfigDir()
* then a default is used which is based on kicad's
* configuration directory code as of September 2015.
*/
wxString Get3DConfigDir( bool createDefault = false );
S3D_PLUGIN_MANAGER* m_Plugins;
/**
* Function SetProjectDir
* sets the current project's working directory; this
* affects the model search path
*/
bool SetProjectDir( const wxString& aProjDir );
PROJECT* m_project;
wxString m_CacheDir;
wxString m_ConfigDir; ///< base configuration path for 3D items.
/**
* Function SetProgramBase
* sets the filename resolver's pointer to the application's
* PGM_BASE instance; the pointer is used to extract the
* local env vars.
*/
void SetProgramBase( PGM_BASE* aBase );
/**
* Function GetProjectDir
* returns the current project's working directory
*/
wxString GetProjectDir( void );
/**
* Function Load
* attempts to load the scene data for a model; it will consult the
* internal cache list and load from cache if possible before invoking
* the load() function of the available plugins.
*
* @param aModelFile [in] is the partial or full path to the model to be loaded
* @return true if the model was successfully loaded, otherwise false.
* The model may fail to load if, for example, the plugin does not
* support rendering of the 3D model.
*/
SCENEGRAPH* Load( const wxString& aModelFile );
FILENAME_RESOLVER* GetResolver( void );
/**
* Function GetFileFilters
* returns the list of file filters retrieved from the plugins;
* this will contain at least the default "All Files (*.*)|*.*"
*
* @return a pointer to the filter list
*/
std::list< wxString > const* GetFileFilters( void ) const;
/**
* Function FlushCache
* frees all data in the cache and by default closes all plugins
*/
void FlushCache( bool closePlugins = true );
/**
* Function ClosePlugins
* unloads plugins to free memory
*/
void ClosePlugins( void );
/**
* Function GetModel
* attempts to load the scene data for a model and to translate it
* into an S3D_MODEL structure for display by a renderer
*
* @param aModelFileName is the full path to the model to be loaded
* @return is a pointer to the render data or NULL if not available
*/
S3DMODEL* GetModel( const wxString& aModelFileName );
wxString GetModelHash( const wxString& aModelFileName );
};
#endif // CACHE_3D_H
+70
View File
@@ -0,0 +1,70 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <common.h>
#include <pgm_base.h>
#include "3d_cache_wrapper.h"
static wxCriticalSection lock3D_wrapper;
CACHE_WRAPPER::CACHE_WRAPPER()
{
return;
}
CACHE_WRAPPER::~CACHE_WRAPPER()
{
return;
}
S3D_CACHE* PROJECT::Get3DCacheManager( bool updateProjDir )
{
wxCriticalSectionLocker lock( lock3D_wrapper );
CACHE_WRAPPER* cw = (CACHE_WRAPPER*) GetElem( ELEM_3DCACHE );
S3D_CACHE* cache = dynamic_cast<S3D_CACHE*>( cw );
// check that we get the expected type of object or NULL
wxASSERT( !cw || cache );
if( !cw )
{
cw = new CACHE_WRAPPER;
cache = dynamic_cast<S3D_CACHE*>( cw );
wxFileName cfgpath;
cfgpath.AssignDir( GetKicadConfigPath() );
cfgpath.AppendDir( wxT( "3d" ) );
cache->SetProgramBase( &Pgm() );
cache->Set3DConfigDir( cfgpath.GetFullPath() );
SetElem( ELEM_3DCACHE, cw );
updateProjDir = true;
}
if( updateProjDir )
cache->SetProjectDir( GetProjectPath() );
return cache;
}
+39
View File
@@ -0,0 +1,39 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef CACHE_WRAPPER_3D_H
#define CACHE_WRAPPER_3D_H
#include <project.h>
#include "3d_cache.h"
class CACHE_WRAPPER : public S3D_CACHE, public PROJECT::_ELEM
{
public:
KICAD_T Type() override { return CACHE_WRAPPER_T; }
CACHE_WRAPPER();
virtual ~CACHE_WRAPPER();
};
#endif // CACHE_WRAPPER_3D_H
+3 -3
View File
@@ -5,7 +5,7 @@
* Copyright (C) 2015 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -36,12 +36,12 @@
#include <wx/string.h>
#include <plugins/3dapi/sg_base.h>
class FP_3DMODEL;
class MODULE_3D_SETTINGS;
struct S3D_INFO
{
S3D_INFO();
S3D_INFO( const FP_3DMODEL& aModel );
S3D_INFO( const MODULE_3D_SETTINGS& aModel );
SGPOINT m_Scale; ///< scaling factors for the 3D footprint shape
SGPOINT m_Rotation; ///< an X,Y,Z rotation (unit = degrees) for the 3D shape
+195 -146
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -27,35 +26,29 @@
#include <iostream>
#include <sstream>
#include <wx/config.h>
#include <wx/dir.h>
#include <wx/dynlib.h>
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/stdpaths.h>
#include <wx/string.h>
#include <common.h>
#include <paths.h>
#include <wx_filename.h>
#include "common.h"
#include "pgm_base.h"
#include "3d_plugin_dir.h"
#include "3d_plugin_manager.h"
#include "plugins/3d/3d_plugin.h"
#include "3d_cache/sg/scenegraph.h"
#include "plugins/ldr/3d/pluginldr3D.h"
/**
* Flag to enable 3D plugin manager debug tracing.
*
* Use "KI_TRACE_EDA_3D_VIEWER" to enable.
*
* @ingroup trace_env_vars
*/
#define MASK_3D_PLUGINMGR "3D_PLUGIN_MANAGER"
S3D_PLUGIN_MANAGER::S3D_PLUGIN_MANAGER()
{
// create the initial file filter list entry
m_FileFilters.emplace_back( _( "All Files" ) + wxT( " (*.*)|*.*" ) );
m_FileFilters.push_back( _( "All Files (*.*)|*.*" ) );
// discover and load plugins
loadPlugins();
@@ -65,19 +58,19 @@ S3D_PLUGIN_MANAGER::S3D_PLUGIN_MANAGER()
{
std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::const_iterator sM = m_ExtMap.begin();
std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::const_iterator eM = m_ExtMap.end();
wxLogTrace( MASK_3D_PLUGINMGR, wxT( " * Extension [plugin name]:\n" ) );
wxLogTrace( MASK_3D_PLUGINMGR, " * Extension [plugin name]:\n" );
while( sM != eM )
{
wxLogTrace( MASK_3D_PLUGINMGR, wxT( " + '%s' [%s]\n" ), sM->first.GetData(),
sM->second->GetKicadPluginName() );
wxLogTrace( MASK_3D_PLUGINMGR, " + '%s' [%s]\n", sM->first.GetData(),
sM->second->GetKicadPluginName() );
++sM;
}
}
else
{
wxLogTrace( MASK_3D_PLUGINMGR, wxT( " * No plugins available\n" ) );
wxLogTrace( MASK_3D_PLUGINMGR, " * No plugins available\n" );
}
@@ -86,19 +79,21 @@ S3D_PLUGIN_MANAGER::S3D_PLUGIN_MANAGER()
/// list of file filters
std::list< wxString >::const_iterator sFF = m_FileFilters.begin();
std::list< wxString >::const_iterator eFF = m_FileFilters.end();
wxLogTrace( MASK_3D_PLUGINMGR, wxT( " * File filters:\n" ) );
wxLogTrace( MASK_3D_PLUGINMGR, " * File filters:\n" );
while( sFF != eFF )
{
wxLogTrace( MASK_3D_PLUGINMGR, wxT( " + '%s'\n" ), (*sFF).GetData() );
wxLogTrace( MASK_3D_PLUGINMGR, " + '%s'\n", (*sFF).GetData() );
++sFF;
}
}
else
{
wxLogTrace( MASK_3D_PLUGINMGR, wxT( " * No file filters available\n" ) );
wxLogTrace( MASK_3D_PLUGINMGR, " * No file filters available\n" );
}
#endif // DEBUG
return;
}
@@ -115,87 +110,89 @@ S3D_PLUGIN_MANAGER::~S3D_PLUGIN_MANAGER()
}
m_Plugins.clear();
return;
}
void S3D_PLUGIN_MANAGER::loadPlugins( void )
{
std::list<wxString> searchpaths;
std::list<wxString> pluginlist;
wxFileName fn;
std::list< wxString > searchpaths;
std::list< wxString > pluginlist;
wxFileName fn;
#ifndef __WXMAC__
if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
#ifdef DEBUG
// set up to work from the build directory
fn.Assign( wxStandardPaths::Get().GetExecutablePath() );
fn.AppendDir( wxT("..") );
fn.AppendDir( wxT("plugins") );
fn.AppendDir( wxT("3d") );
std::string testpath = std::string( fn.GetPathWithSep().ToUTF8() );
checkPluginPath( testpath, searchpaths );
// add subdirectories too
wxDir debugPluginDir;
wxString subdir;
debugPluginDir.Open( testpath );
if( debugPluginDir.IsOpened() &&
debugPluginDir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS ) )
{
// set up to work from the build directory
fn.Assign( wxStandardPaths::Get().GetExecutablePath() );
fn.AppendDir( wxT( ".." ) );
fn.AppendDir( wxT( "plugins" ) );
fn.AppendDir( wxT( "3d" ) );
checkPluginPath( testpath + subdir, searchpaths );
std::string testpath = std::string( fn.GetPathWithSep().ToUTF8() );
checkPluginPath( testpath, searchpaths );
// add subdirectories too
wxDir debugPluginDir;
wxString subdir;
debugPluginDir.Open( testpath );
if( debugPluginDir.IsOpened()
&& debugPluginDir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS ) )
{
while( debugPluginDir.GetNext( &subdir ) )
checkPluginPath( testpath + subdir, searchpaths );
while( debugPluginDir.GetNext( &subdir ) )
checkPluginPath( testpath + subdir, searchpaths );
}
}
#endif
fn.AssignDir( PATHS::GetStockPlugins3DPath() );
#ifndef _WIN32
// PLUGINDIR = CMAKE_INSTALL_FULL_LIBDIR path is the absolute path
// corresponding to the install path used for constructing KICAD_USER_PLUGIN
wxString tfname = wxString::FromUTF8Unchecked( PLUGINDIR );
fn.Assign( tfname, "");
fn.AppendDir( "kicad" );
#else
// on windows the plugins directory is within the executable's directory
fn.Assign( wxStandardPaths::Get().GetExecutablePath() );
#endif
fn.AppendDir( wxT( "plugins" ) );
fn.AppendDir( wxT( "3d" ) );
// checks plugin directory relative to executable path
checkPluginPath( std::string( fn.GetPathWithSep().ToUTF8() ), searchpaths );
// check for per-user third party plugins
// note: GetUserDataDir() gives '.pcbnew' rather than '.kicad' since it uses the exe name;
fn.Assign( wxStandardPaths::Get().GetUserDataDir(), "" );
fn.RemoveLastDir();
#ifdef _WIN32
fn.AppendDir( wxT( "kicad" ) );
#else
fn.AppendDir( wxT( ".kicad" ) );
#endif
fn.AppendDir( wxT( "plugins" ) );
fn.AppendDir( wxT( "3d" ) );
checkPluginPath( fn.GetPathWithSep(), searchpaths );
#else
if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
{
// Exe will be at <build_dir>/pcbnew/pcbnew.app/Contents/MacOS/pcbnew for standalone
// Plugin will be at <build_dir>/kicad/KiCad.app/Contents/PlugIns/3d
fn.Assign( wxStandardPaths::Get().GetExecutablePath() );
if( fn.GetName() == wxT( "kicad" ) )
{
fn.AppendDir( wxT( ".." ) ); // Contents
}
else
{
fn.AppendDir( wxT( ".." ) ); // Contents
fn.AppendDir( wxT( ".." ) ); // pcbnew.app
fn.AppendDir( wxT( ".." ) ); // pcbnew
fn.AppendDir( wxT( ".." ) ); // Build root
fn.AppendDir( wxT( "kicad" ) );
fn.AppendDir( wxT( "KiCad.app" ) );
fn.AppendDir( wxT( "Contents" ) );
}
// Search path on OS X is
// (1) User ~/Library/Application Support/kicad/PlugIns/3d
checkPluginPath( GetOSXKicadUserDataDir() + wxT( "/PlugIns/3d" ), searchpaths );
// (2) Machine /Library/Application Support/kicad/PlugIns/3d
checkPluginPath( GetOSXKicadMachineDataDir() + wxT( "/PlugIns/3d" ), searchpaths );
// (3) Bundle kicad.app/Contents/PlugIns/3d
fn.Assign( Pgm().GetExecutablePath() );
fn.AppendDir( wxT( "Contents" ) );
fn.AppendDir( wxT( "PlugIns" ) );
fn.AppendDir( wxT( "3d" ) );
checkPluginPath( fn.GetPathWithSep(), searchpaths );
fn.AppendDir( wxT( "PlugIns" ) );
fn.AppendDir( wxT( "3d" ) );
fn.MakeAbsolute();
std::string testpath = std::string( fn.GetPathWithSep().ToUTF8() );
checkPluginPath( testpath, searchpaths );
// Also check when running KiCad manager from build dir
}
else
{
// Search path on OS X is
// (1) Machine /Library/Application Support/kicad/PlugIns/3d
checkPluginPath( PATHS::GetOSXKicadMachineDataDir() + wxT( "/PlugIns/3d" ), searchpaths );
// (2) Bundle kicad.app/Contents/PlugIns/3d
fn.AssignDir( PATHS::GetStockPlugins3DPath() );
checkPluginPath( fn.GetPathWithSep(), searchpaths );
}
#endif
std::list< wxString >::iterator sPL = searchpaths.begin();
@@ -203,9 +200,14 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void )
while( sPL != ePL )
{
wxLogTrace( MASK_3D_PLUGINMGR, wxT( "%s:%s:%d * [DEBUG] searching path: '%s'" ),
__FILE__, __FUNCTION__, __LINE__, (*sPL).ToUTF8() );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << ":\n";
ostr << " * [DEBUG] searching path: '" << (*sPL).ToUTF8() << "'";
wxLogTrace( MASK_3D_PLUGINMGR, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
listPlugins( *sPL, pluginlist );
++sPL;
}
@@ -222,21 +224,32 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void )
if( pp->Open( sPL->ToUTF8() ) )
{
wxLogTrace( MASK_3D_PLUGINMGR, wxT( "%s:%s:%d * [DEBUG] adding plugin" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << ":\n";
ostr << "* [DEBUG] adding plugin";
wxLogTrace( MASK_3D_PLUGINMGR, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
m_Plugins.push_back( pp );
int nf = pp->GetNFilters();
wxLogTrace( MASK_3D_PLUGINMGR, wxT( "%s:%s:%d * [DEBUG] adding %d filters" ),
__FILE__, __FUNCTION__, __LINE__, nf );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] adding " << nf << " filters";
wxLogTrace( MASK_3D_PLUGINMGR, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
for( int i = 0; i < nf; ++i )
{
char const* cp = pp->GetFileFilter( i );
if( cp )
addFilterString( cp );
addFilterString( wxString::FromUTF8Unchecked( cp ) );
}
addExtensionMap( pp );
@@ -246,24 +259,39 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void )
}
else
{
wxLogTrace( MASK_3D_PLUGINMGR, wxT( "%s:%s:%d * [DEBUG] deleting plugin" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << ":\n";
ostr << "* [DEBUG] deleting plugin";
wxLogTrace( MASK_3D_PLUGINMGR, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
delete pp;
}
++sPL;
}
wxLogTrace( MASK_3D_PLUGINMGR, wxT( "%s:%s:%d * [DEBUG] plugins loaded" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << ":\n";
ostr << "* [DEBUG] plugins loaded";
wxLogTrace( MASK_3D_PLUGINMGR, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return;
}
void S3D_PLUGIN_MANAGER::listPlugins( const wxString& aPath, std::list< wxString >& aPluginList )
void S3D_PLUGIN_MANAGER::listPlugins( const wxString& aPath,
std::list< wxString >& aPluginList )
{
// list potential plugins given a search path
wxString nameFilter; // filter for user-loadable libraries (aka footprints)
wxString nameFilter; // filter for user-loadable libraries (aka modules)
wxString lName; // stores name of enumerated files
wxString fName; // full name of file
wxDir wd;
@@ -282,7 +310,7 @@ void S3D_PLUGIN_MANAGER::listPlugins( const wxString& aPath, std::list< wxString
// Per definition a loadable "xxx.bundle" is similar to an "xxx.app" app
// bundle being a folder with some special content in it. We obviously don't
// want to have that here for our loadable module, so just use ".so".
nameFilter.Append( wxS( ".so" ) );
nameFilter.Append( ".so" );
#endif
wxString lp = wd.GetNameWithSep();
@@ -300,20 +328,27 @@ void S3D_PLUGIN_MANAGER::listPlugins( const wxString& aPath, std::list< wxString
}
wd.Close();
return;
}
void S3D_PLUGIN_MANAGER::checkPluginName( const wxString& aPath,
std::list< wxString >& aPluginList )
std::list< wxString >& aPluginList )
{
// check the existence of a plugin name and add it to the list
if( aPath.empty() || !wxFileName::FileExists( aPath ) )
return;
wxFileName path( ExpandEnvVarSubstitutions( aPath, nullptr ) );
wxFileName path;
path.Normalize( FN_NORMALIZE_FLAGS );
if( aPath.StartsWith( "${" ) || aPath.StartsWith( "$(" ) )
path.Assign( ExpandEnvVarSubstitutions( aPath ) );
else
path.Assign( aPath );
path.Normalize();
// determine if the path is already in the list
wxString wxpath = path.GetFullPath();
@@ -328,34 +363,37 @@ void S3D_PLUGIN_MANAGER::checkPluginName( const wxString& aPath,
++bl;
}
// prevent loading non-plugin dlls
if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
{
if( !path.GetName().StartsWith( "s3d_plugin" )
&& !path.GetName().StartsWith( "libs3d_plugin" ) )
{
return;
}
}
aPluginList.push_back( wxpath );
wxLogTrace( MASK_3D_PLUGINMGR, wxT( " * [INFO] found 3D plugin '%s'\n" ), wxpath.GetData() );
#ifdef DEBUG
wxLogTrace( MASK_3D_PLUGINMGR, " * [INFO] found 3D plugin '%s'\n",
wxpath.GetData() );
#endif
return;
}
void S3D_PLUGIN_MANAGER::checkPluginPath( const wxString& aPath,
std::list< wxString >& aSearchList )
std::list< wxString >& aSearchList )
{
// check the existence of a path and add it to the path search list
if( aPath.empty() )
return;
wxLogTrace( MASK_3D_PLUGINMGR, wxT( " * [INFO] checking if valid plugin directory '%s'\n" ),
aPath.GetData() );
#ifdef DEBUG
wxLogTrace( MASK_3D_PLUGINMGR, " * [INFO] checking for 3D plugins in '%s'\n",
aPath.GetData() );
#endif
wxFileName path;
path.AssignDir( aPath );
path.Normalize( FN_NORMALIZE_FLAGS );
if( aPath.StartsWith( "${" ) || aPath.StartsWith( "$(" ) )
path.Assign( ExpandEnvVarSubstitutions( aPath ), "" );
else
path.Assign( aPath, "" );
path.Normalize();
if( !wxFileName::DirExists( path.GetFullPath() ) )
return;
@@ -374,6 +412,8 @@ void S3D_PLUGIN_MANAGER::checkPluginPath( const wxString& aPath,
}
aSearchList.push_back( wxpath );
return;
}
@@ -402,13 +442,19 @@ void S3D_PLUGIN_MANAGER::addFilterString( const wxString& aFilterString )
void S3D_PLUGIN_MANAGER::addExtensionMap( KICAD_PLUGIN_LDR_3D* aPlugin )
{
// add entries to the extension map
if( nullptr == aPlugin )
if( NULL == aPlugin )
return;
int nExt = aPlugin->GetNExtensions();
wxLogTrace( MASK_3D_PLUGINMGR, wxT( "%s:%s:%d * [INFO] adding %d extensions" ),
__FILE__, __FUNCTION__, __LINE__, nExt );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] adding " << nExt << " extensions";
wxLogTrace( MASK_3D_PLUGINMGR, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
for( int i = 0; i < nExt; ++i )
{
@@ -416,18 +462,20 @@ void S3D_PLUGIN_MANAGER::addExtensionMap( KICAD_PLUGIN_LDR_3D* aPlugin )
wxString ws;
if( cp )
ws = wxString( cp );
ws = wxString::FromUTF8Unchecked( cp );
if( !ws.empty() )
{
m_ExtMap.emplace( ws, aPlugin );
m_ExtMap.insert( std::pair< const wxString, KICAD_PLUGIN_LDR_3D* >( ws, aPlugin ) );
}
}
return;
}
std::list< wxString > const* S3D_PLUGIN_MANAGER::GetFileFilters( void ) const noexcept
std::list< wxString > const* S3D_PLUGIN_MANAGER::GetFileFilters( void ) const
{
return &m_FileFilters;
}
@@ -436,26 +484,18 @@ std::list< wxString > const* S3D_PLUGIN_MANAGER::GetFileFilters( void ) const no
SCENEGRAPH* S3D_PLUGIN_MANAGER::Load3DModel( const wxString& aFileName, std::string& aPluginInfo )
{
wxFileName raw( aFileName );
wxString ext_to_find = raw.GetExt();
wxString ext = raw.GetExt();
#ifdef _WIN32
#ifdef _WIN32
// note: plugins only have a lowercase filter within Windows; including an uppercase
// filter will result in duplicate file entries and should be avoided.
ext_to_find.MakeLower();
#endif
// .gz files are compressed versions that may have additional information in the previous
// extension.
if( ext_to_find == wxT( "gz" ) )
{
wxFileName second( raw.GetName() );
ext_to_find = second.GetExt() + wxT( ".gz" );
}
ext.LowerCase();
#endif
std::pair < std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::iterator,
std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::iterator > items;
items = m_ExtMap.equal_range( ext_to_find );
items = m_ExtMap.equal_range( ext );
std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::iterator sL = items.first;
while( sL != items.second )
@@ -464,7 +504,7 @@ SCENEGRAPH* S3D_PLUGIN_MANAGER::Load3DModel( const wxString& aFileName, std::str
{
SCENEGRAPH* sp = sL->second->Load( aFileName.ToUTF8() );
if( nullptr != sp )
if( NULL != sp )
{
sL->second->GetPluginInfo( aPluginInfo );
return sp;
@@ -474,7 +514,7 @@ SCENEGRAPH* S3D_PLUGIN_MANAGER::Load3DModel( const wxString& aFileName, std::str
++sL;
}
return nullptr;
return NULL;
}
@@ -483,20 +523,28 @@ void S3D_PLUGIN_MANAGER::ClosePlugins( void )
std::list< KICAD_PLUGIN_LDR_3D* >::iterator sP = m_Plugins.begin();
std::list< KICAD_PLUGIN_LDR_3D* >::iterator eP = m_Plugins.end();
wxLogTrace( MASK_3D_PLUGINMGR, wxT( "%s:%s:%d * [INFO] closing %d extensions" ),
__FILE__, __FUNCTION__, __LINE__, static_cast<int>( m_Plugins.size() ) );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] closing " << m_Plugins.size() << " plugins";
wxLogTrace( MASK_3D_PLUGINMGR, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
while( sP != eP )
{
(*sP)->Close();
++sP;
}
return;
}
bool S3D_PLUGIN_MANAGER::CheckTag( const char* aTag )
{
if( nullptr == aTag || aTag[0] == 0 || m_Plugins.empty() )
if( NULL == aTag || aTag[0] == 0 || m_Plugins.empty() )
return false;
std::string tname = aTag;
@@ -519,7 +567,8 @@ bool S3D_PLUGIN_MANAGER::CheckTag( const char* aTag )
ptag.clear();
(*pS)->GetPluginInfo( ptag );
// if the plugin name matches then the version must also match
// if the plugin name matches then the version
// must also match
if( !ptag.compare( 0, pname.size(), pname ) )
{
if( ptag.compare( tname ) )
+37 -35
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -41,35 +40,16 @@ class SCENEGRAPH;
class S3D_PLUGIN_MANAGER
{
public:
S3D_PLUGIN_MANAGER();
virtual ~S3D_PLUGIN_MANAGER();
/**
* Return the list of file filters; this will contain at least the default
* "All Files (*.*)|*.*" and the file filters supported by any available plugins.
*
* @return a pointer to the internal filter list.
*/
std::list< wxString > const* GetFileFilters( void ) const noexcept;
SCENEGRAPH* Load3DModel( const wxString& aFileName, std::string& aPluginInfo );
/**
* Iterate through all discovered plugins and closes them to reclaim memory.
*
* The individual plugins will be automatically reloaded as calls are made to load
* specific models.
*/
void ClosePlugins( void );
/**
* Check the given tag and returns true if the plugin named in the tag is not loaded
* or the plugin is loaded and the version matches.
*/
bool CheckTag( const char* aTag );
private:
/// list of discovered plugins
std::list< KICAD_PLUGIN_LDR_3D* > m_Plugins;
/// mapping of extensions to available plugins
std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* > m_ExtMap;
/// list of file filters
std::list< wxString > m_FileFilters;
/// load plugins
void loadPlugins( void );
@@ -88,14 +68,36 @@ private:
/// add entries to the extension map
void addExtensionMap( KICAD_PLUGIN_LDR_3D* aPlugin );
/// list of discovered plugins
std::list< KICAD_PLUGIN_LDR_3D* > m_Plugins;
public:
S3D_PLUGIN_MANAGER();
virtual ~S3D_PLUGIN_MANAGER();
/// mapping of extensions to available plugins
std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* > m_ExtMap;
/**
* Function GetFileFilters
* returns the list of file filters; this will contain at least
* the default "All Files (*.*)|*.*" and the file filters supported
* by any available plugins
*
* @return a pointer to the internal filter list
*/
std::list< wxString > const* GetFileFilters( void ) const;
/// list of file filters
std::list< wxString > m_FileFilters;
SCENEGRAPH* Load3DModel( const wxString& aFileName, std::string& aPluginInfo );
/**
* Function ClosePlugins
* iterates through all discovered plugins and closes them to
* reclaim memory. The individual plugins will be automatically
* reloaded as calls are made to load specific models.
*/
void ClosePlugins( void );
/**
* Function CheckTag
* checks the given tag and returns true if the plugin named in the tag
* is not loaded or the plugin is loaded and the version matches
*/
bool CheckTag( const char* aTag );
};
#endif // PLUGIN_MANAGER_3D_H
@@ -0,0 +1,59 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <wx/filename.h>
#include "3d_info.h"
#include "3d_cache.h"
#include "plugins/3dapi/ifsg_api.h"
#include "3d_cache_dialogs.h"
#include "dialog_configure_paths.h"
#include "dlg_select_3dmodel.h"
bool S3D::Select3DModel( wxWindow* aParent, S3D_CACHE* aCache,
wxString& prevModelSelectDir, int& prevModelWildcard, MODULE_3D_SETTINGS* aModel )
{
if( NULL == aModel )
return false;
DLG_SELECT_3DMODEL* dm = new DLG_SELECT_3DMODEL( aParent, aCache, aModel,
prevModelSelectDir, prevModelWildcard );
if( wxID_OK == dm->ShowModal() )
{
delete dm;
return true;
}
delete dm;
return false;
}
bool S3D::Configure3DPaths( wxWindow* aParent, FILENAME_RESOLVER* aResolver )
{
DIALOG_CONFIGURE_PATHS dlg( aParent, aResolver );
return( dlg.ShowModal() == wxID_OK );
}
@@ -0,0 +1,40 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef CACHE_DIALOGS_3D_H
#define CACHE_DIALOGS_3D_H
#include <wx/window.h>
class S3D_CACHE;
class FILENAME_RESOLVER;
namespace S3D
{
bool Select3DModel( wxWindow* aParent, S3D_CACHE* aCache,
wxString& prevModelSelectDir, int& prevModelWildcard, MODULE_3D_SETTINGS* aModel );
bool Configure3DPaths( wxWindow* aParent, FILENAME_RESOLVER* aResolver );
}
#endif // CACHE_DIALOGS_3D_H
@@ -0,0 +1,294 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2017-2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <set>
#include "dlg_select_3dmodel.h"
#include "project.h"
#include "3d_cache/3d_info.h"
#include "3d_cache/3d_cache.h"
#include "3d_cache_dialogs.h"
#include <3d_model_viewer/c3d_model_viewer.h>
#include <common_ogl/cogl_att_list.h>
#include <pcbnew/class_module.h>
#define ID_FILE_TREE ( wxID_LAST + 1 )
#define ID_SET_DIR ( ID_FILE_TREE + 1 )
#define ID_CFG_PATHS ( ID_SET_DIR + 1 )
wxBEGIN_EVENT_TABLE( DLG_SELECT_3DMODEL, DIALOG_SHIM )
EVT_DIRCTRL_SELECTIONCHANGED( ID_FILE_TREE, DLG_SELECT_3DMODEL::OnSelectionChanged )
EVT_DIRCTRL_FILEACTIVATED( ID_FILE_TREE, DLG_SELECT_3DMODEL::OnFileActivated )
EVT_CHOICE( ID_SET_DIR, DLG_SELECT_3DMODEL::SetRootDir )
EVT_BUTTON( ID_CFG_PATHS, DLG_SELECT_3DMODEL::Cfg3DPaths )
wxEND_EVENT_TABLE()
DLG_SELECT_3DMODEL::DLG_SELECT_3DMODEL( wxWindow* aParent, S3D_CACHE* aCacheManager,
MODULE_3D_SETTINGS* aModelItem, wxString& prevModelSelectDir, int& prevModelWildcard ) :
DIALOG_SHIM( aParent, wxID_ANY, _( "Select 3D Model" ), wxDefaultPosition,
wxSize( 500,200 ), wxCAPTION | wxRESIZE_BORDER | wxCLOSE_BOX
| wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU ),
m_model( aModelItem ), m_cache( aCacheManager ), m_previousDir( prevModelSelectDir ),
m_previousFilterIndex( prevModelWildcard )
{
SetSizeHints( wxSize( 500,200 ), wxDefaultSize );
if( NULL != m_cache )
m_resolver = m_cache->GetResolver();
else
m_resolver = NULL;
wxBoxSizer* bSizer0 = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bSizer1 = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* bSizer2 = new wxBoxSizer( wxVERTICAL );
// set to NULL to avoid segfaults when m_FileTree is instantiated
// and wxGenericDirCtrl events are posted
m_modelViewer = NULL;
dirChoices = NULL;
m_FileTree = new wxGenericDirCtrl( this, ID_FILE_TREE, prevModelSelectDir, wxDefaultPosition,
wxSize( 300,100 ), wxDIRCTRL_3D_INTERNAL | wxDIRCTRL_EDIT_LABELS
| wxDIRCTRL_SELECT_FIRST | wxDIRCTRL_SHOW_FILTERS | wxBORDER_SIMPLE, wxEmptyString, 0 );
m_FileTree->ShowHidden( false );
m_FileTree->SetMinSize( wxSize( 300, 400 ) );
m_FileTree->SetLabel( wxT( "3D_MODEL_SELECTOR" ) );
bSizer2->Add( m_FileTree, 1, wxEXPAND | wxALL, 5 );
bSizer1->Add( bSizer2, 3, wxEXPAND, 5 );
m_modelViewer = new C3D_MODEL_VIEWER( this, COGL_ATT_LIST::GetAttributesList( true ), m_cache );
m_modelViewer->SetMinSize( wxSize( 500, 400 ) );
bSizer1->Add( m_modelViewer, 5, wxEXPAND | wxALL | wxCENTER, 5 );
// create the filter list
if( NULL != m_cache )
{
std::list< wxString > const* fl = m_cache->GetFileFilters();
std::list< wxString >::const_iterator sL = fl->begin();
std::list< wxString >::const_iterator eL = fl->end();
wxString filter;
while( sL != eL )
{
filter.Append( *sL );
++sL;
if( sL != eL )
filter.Append( wxT( "|" ) );
}
if( !filter.empty() )
m_FileTree->SetFilter( filter );
else
m_FileTree->SetFilter( wxFileSelectorDefaultWildcardStr );
if( prevModelWildcard >= 0 && prevModelWildcard < (int)fl->size() )
m_FileTree->SetFilterIndex( prevModelWildcard );
else
{
prevModelWildcard = 0;
m_FileTree->SetFilterIndex( 0 );
}
}
else
{
m_FileTree->SetFilter( wxFileSelectorDefaultWildcardStr );
prevModelWildcard = 0;
m_FileTree->SetFilterIndex( 0 );
}
// Add the path choice box and config button
wxBoxSizer* hboxDirChoice = new wxBoxSizer( wxHORIZONTAL );
dirChoices = new wxChoice( this, ID_SET_DIR, wxDefaultPosition, wxSize( 320, 20 ) );
dirChoices->SetMinSize( wxSize( 320, 12 ) );
wxStaticText* stDirChoice = new wxStaticText( this, -1, _( "Paths:" ) );
wxButton* cfgPaths = new wxButton( this, ID_CFG_PATHS, _( "Configure Paths" ) );
hboxDirChoice->Add( stDirChoice, 0, wxALL | wxCENTER, 5 );
hboxDirChoice->Add( dirChoices, 1, wxEXPAND | wxALL, 5 );
hboxDirChoice->Add( cfgPaths, 0, wxALL, 5 );
wxButton* btn_OK = new wxButton( this, wxID_OK, _( "OK" ) );
wxButton* btn_Cancel = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
wxStdDialogButtonSizer* hSizer1 = new wxStdDialogButtonSizer();
hSizer1->AddButton( btn_OK );
hSizer1->AddButton( btn_Cancel );
hSizer1->Realize();
bSizer0->Add( bSizer1, 1, wxALL | wxEXPAND, 5 );
bSizer0->Add( hboxDirChoice, 0, wxALL | wxEXPAND, 5 );
bSizer0->Add( hSizer1, 0, wxALL | wxEXPAND, 5 );
updateDirChoiceList();
SetSizerAndFit( bSizer0 );
Layout();
Centre( wxBOTH );
m_modelViewer->Refresh();
m_modelViewer->SetFocus();
}
bool DLG_SELECT_3DMODEL::TransferDataFromWindow()
{
if( NULL == m_model || NULL == m_FileTree )
return true;
m_model->m_Scale.x = 1.0;
m_model->m_Scale.y = 1.0;
m_model->m_Scale.z = 1.0;
m_model->m_Rotation.x = 0.0;
m_model->m_Rotation.y = 0.0;
m_model->m_Rotation.z = 0.0;
m_model->m_Offset = m_model->m_Rotation;
m_model->m_Filename.clear();
wxString name = m_FileTree->GetFilePath();
if( name.empty() )
return true;
m_previousDir = m_FileTree->GetPath();
m_previousFilterIndex = m_FileTree->GetFilterIndex();
// file selection mode: retrieve the filename and specify a
// path relative to one of the config paths
wxFileName fname = m_FileTree->GetFilePath();
fname.Normalize();
m_model->m_Filename = m_resolver->ShortenPath( fname.GetFullPath() );
return true;
}
void DLG_SELECT_3DMODEL::OnSelectionChanged( wxTreeEvent& event )
{
if( m_modelViewer )
m_modelViewer->Set3DModel( m_FileTree->GetFilePath() );
event.Skip();
return;
}
void DLG_SELECT_3DMODEL::OnFileActivated( wxTreeEvent& event )
{
if( m_modelViewer )
m_modelViewer->Set3DModel( m_FileTree->GetFilePath() );
event.Skip();
SetEscapeId( wxID_OK );
Close();
return;
}
void DLG_SELECT_3DMODEL::SetRootDir( wxCommandEvent& event )
{
if( m_FileTree && dirChoices->GetSelection() > 0 )
m_FileTree->SetPath( dirChoices->GetString( dirChoices->GetSelection() ) );
return;
}
void DLG_SELECT_3DMODEL::Cfg3DPaths( wxCommandEvent& event )
{
if( S3D::Configure3DPaths( this, m_resolver ) )
updateDirChoiceList();
}
void DLG_SELECT_3DMODEL::updateDirChoiceList( void )
{
if( NULL == m_FileTree || NULL == m_resolver || NULL == dirChoices )
return;
std::list< SEARCH_PATH > const* md = m_resolver->GetPaths();
std::list< SEARCH_PATH >::const_iterator sL = md->begin();
std::list< SEARCH_PATH >::const_iterator eL = md->end();
std::set< wxString > cl;
wxString prjDir;
// extract the current project dir
if( sL != eL )
{
prjDir = sL->m_pathexp;
++sL;
}
while( sL != eL )
{
if( !sL->m_pathexp.empty() && sL->m_pathexp.compare( prjDir ) )
cl.insert( sL->m_pathexp );
++sL;
}
if( !cl.empty() )
{
unsigned int choice = 0;
dirChoices->Clear();
dirChoices->Append( "" ); //Insert a blank string at the beginning to allow selection
if( !prjDir.empty() )
{
dirChoices->Append( prjDir );
if( prjDir == m_FileTree->GetPath() )
choice = 1;
}
std::set< wxString >::const_iterator sI = cl.begin();
std::set< wxString >::const_iterator eI = cl.end();
while( sI != eI )
{
if( *sI == m_FileTree->GetPath() )
choice = dirChoices->GetCount();
dirChoices->Append( *sI );
++sI;
}
dirChoices->Select( choice );
}
return;
}
@@ -0,0 +1,78 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file dlg_select_3dmodel.h
* creates a dialog to select 3D model files
*/
#ifndef DLG_SELECT_3DMODEL_H
#define DLG_SELECT_3DMODEL_H
#include <wx/event.h>
#include <wx/stattext.h>
#include <wx/button.h>
#include <wx/dialog.h>
#include <wx/dirctrl.h>
#include <wx/sizer.h>
#include <wx/frame.h>
#include <dialog_shim.h>
class MODULE_3D_SETTINGS;
class S3D_CACHE;
class FILENAME_RESOLVER;
class C3D_MODEL_VIEWER;
class DLG_SELECT_3DMODEL : public DIALOG_SHIM
{
private:
MODULE_3D_SETTINGS* m_model; // data for the selected model
S3D_CACHE* m_cache; // cache manager
FILENAME_RESOLVER* m_resolver; // 3D filename resolver
wxString& m_previousDir;
int& m_previousFilterIndex;
wxGenericDirCtrl* m_FileTree;
C3D_MODEL_VIEWER* m_modelViewer;
wxChoice* dirChoices;
void updateDirChoiceList( void );
public:
DLG_SELECT_3DMODEL( wxWindow* aParent, S3D_CACHE* aCacheManager, MODULE_3D_SETTINGS* aModelItem,
wxString& prevModelSelectDir, int& prevModelWildcard );
bool TransferDataFromWindow() override;
void OnSelectionChanged( wxTreeEvent& event );
void OnFileActivated( wxTreeEvent& event );
void SetRootDir( wxCommandEvent& event );
void Cfg3DPaths( wxCommandEvent& event );
wxDECLARE_EVENT_TABLE();
};
#endif // DLG_SELECT_3DMODEL_H
@@ -0,0 +1,310 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.9.0 Nov 1 2020)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "panel_prev_3d_base.h"
///////////////////////////////////////////////////////////////////////////
PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name )
{
wxBoxSizer* bSizermain;
bSizermain = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* bSizerLeft;
bSizerLeft = new wxBoxSizer( wxVERTICAL );
wxStaticBoxSizer* sbSizerScale;
sbSizerScale = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Scale") ), wxVERTICAL );
wxFlexGridSizer* fgSizerScale;
fgSizerScale = new wxFlexGridSizer( 0, 3, 0, 0 );
fgSizerScale->SetFlexibleDirection( wxBOTH );
fgSizerScale->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_staticText1 = new wxStaticText( sbSizerScale->GetStaticBox(), wxID_ANY, _("X:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText1->Wrap( -1 );
fgSizerScale->Add( m_staticText1, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
xscale = new wxTextCtrl( sbSizerScale->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerScale->Add( xscale, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
m_spinXscale = new wxSpinButton( sbSizerScale->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
fgSizerScale->Add( m_spinXscale, 0, wxALIGN_CENTER_VERTICAL, 5 );
m_staticText2 = new wxStaticText( sbSizerScale->GetStaticBox(), wxID_ANY, _("Y:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText2->Wrap( -1 );
fgSizerScale->Add( m_staticText2, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
yscale = new wxTextCtrl( sbSizerScale->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerScale->Add( yscale, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
m_spinYscale = new wxSpinButton( sbSizerScale->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
fgSizerScale->Add( m_spinYscale, 0, wxALIGN_CENTER_VERTICAL, 5 );
m_staticText3 = new wxStaticText( sbSizerScale->GetStaticBox(), wxID_ANY, _("Z:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText3->Wrap( -1 );
fgSizerScale->Add( m_staticText3, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 );
zscale = new wxTextCtrl( sbSizerScale->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerScale->Add( zscale, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 );
m_spinZscale = new wxSpinButton( sbSizerScale->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
fgSizerScale->Add( m_spinZscale, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5 );
sbSizerScale->Add( fgSizerScale, 0, wxEXPAND|wxRIGHT|wxLEFT, 10 );
bSizerLeft->Add( sbSizerScale, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );
wxStaticBoxSizer* sbSizerRotation;
sbSizerRotation = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Rotation") ), wxVERTICAL );
wxFlexGridSizer* fgSizerRotate;
fgSizerRotate = new wxFlexGridSizer( 0, 3, 0, 0 );
fgSizerRotate->SetFlexibleDirection( wxBOTH );
fgSizerRotate->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_staticText11 = new wxStaticText( sbSizerRotation->GetStaticBox(), wxID_ANY, _("X:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText11->Wrap( -1 );
fgSizerRotate->Add( m_staticText11, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
xrot = new wxTextCtrl( sbSizerRotation->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerRotate->Add( xrot, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
m_spinXrot = new wxSpinButton( sbSizerRotation->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
fgSizerRotate->Add( m_spinXrot, 0, wxALIGN_CENTER_VERTICAL, 5 );
m_staticText21 = new wxStaticText( sbSizerRotation->GetStaticBox(), wxID_ANY, _("Y:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText21->Wrap( -1 );
fgSizerRotate->Add( m_staticText21, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
yrot = new wxTextCtrl( sbSizerRotation->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerRotate->Add( yrot, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
m_spinYrot = new wxSpinButton( sbSizerRotation->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
fgSizerRotate->Add( m_spinYrot, 0, wxALIGN_CENTER_VERTICAL, 5 );
m_staticText31 = new wxStaticText( sbSizerRotation->GetStaticBox(), wxID_ANY, _("Z:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText31->Wrap( -1 );
fgSizerRotate->Add( m_staticText31, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 );
zrot = new wxTextCtrl( sbSizerRotation->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerRotate->Add( zrot, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 );
m_spinZrot = new wxSpinButton( sbSizerRotation->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
fgSizerRotate->Add( m_spinZrot, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5 );
sbSizerRotation->Add( fgSizerRotate, 0, wxEXPAND|wxRIGHT|wxLEFT, 10 );
bSizerLeft->Add( sbSizerRotation, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );
wxStaticBoxSizer* sbSizerOffset;
sbSizerOffset = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Offset") ), wxVERTICAL );
wxFlexGridSizer* fgSizerOffset;
fgSizerOffset = new wxFlexGridSizer( 0, 3, 0, 0 );
fgSizerOffset->SetFlexibleDirection( wxBOTH );
fgSizerOffset->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_staticText12 = new wxStaticText( sbSizerOffset->GetStaticBox(), wxID_ANY, _("X:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText12->Wrap( -1 );
fgSizerOffset->Add( m_staticText12, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
xoff = new wxTextCtrl( sbSizerOffset->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerOffset->Add( xoff, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
m_spinXoffset = new wxSpinButton( sbSizerOffset->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
fgSizerOffset->Add( m_spinXoffset, 0, wxALIGN_CENTER_VERTICAL, 5 );
m_staticText22 = new wxStaticText( sbSizerOffset->GetStaticBox(), wxID_ANY, _("Y:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText22->Wrap( -1 );
fgSizerOffset->Add( m_staticText22, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
yoff = new wxTextCtrl( sbSizerOffset->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerOffset->Add( yoff, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
m_spinYoffset = new wxSpinButton( sbSizerOffset->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
fgSizerOffset->Add( m_spinYoffset, 0, wxALIGN_CENTER_VERTICAL, 5 );
m_staticText32 = new wxStaticText( sbSizerOffset->GetStaticBox(), wxID_ANY, _("Z:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText32->Wrap( -1 );
fgSizerOffset->Add( m_staticText32, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 );
zoff = new wxTextCtrl( sbSizerOffset->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerOffset->Add( zoff, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 );
m_spinZoffset = new wxSpinButton( sbSizerOffset->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
fgSizerOffset->Add( m_spinZoffset, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5 );
sbSizerOffset->Add( fgSizerOffset, 0, wxEXPAND|wxLEFT|wxRIGHT, 10 );
bSizerLeft->Add( sbSizerOffset, 0, wxEXPAND|wxALL, 5 );
bSizermain->Add( bSizerLeft, 0, 0, 5 );
wxBoxSizer* bSizerRight;
bSizerRight = new wxBoxSizer( wxVERTICAL );
wxStaticText* staticPreviewLabel;
staticPreviewLabel = new wxStaticText( this, wxID_ANY, _("Preview"), wxDefaultPosition, wxDefaultSize, 0 );
staticPreviewLabel->Wrap( -1 );
staticPreviewLabel->SetFont( wxFont( 11, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) );
bSizerRight->Add( staticPreviewLabel, 0, wxALL, 5 );
m_SizerPanelView = new wxBoxSizer( wxVERTICAL );
bSizerRight->Add( m_SizerPanelView, 1, wxEXPAND|wxBOTTOM, 5 );
bSizermain->Add( bSizerRight, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 4 );
wxBoxSizer* bSizer3DButtons;
bSizer3DButtons = new wxBoxSizer( wxVERTICAL );
bSizer3DButtons->Add( 0, 0, 0, wxEXPAND|wxTOP, 4 );
m_bpvISO = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 );
m_bpvISO->SetToolTip( _("Change to isometric perspective") );
bSizer3DButtons->Add( m_bpvISO, 0, wxTOP|wxBOTTOM, 5 );
m_bpvLeft = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 );
bSizer3DButtons->Add( m_bpvLeft, 0, 0, 5 );
m_bpvRight = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 );
bSizer3DButtons->Add( m_bpvRight, 0, wxTOP, 5 );
m_bpvFront = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 );
bSizer3DButtons->Add( m_bpvFront, 0, wxTOP, 5 );
m_bpvBack = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 );
bSizer3DButtons->Add( m_bpvBack, 0, wxTOP, 5 );
m_bpvTop = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 );
bSizer3DButtons->Add( m_bpvTop, 0, wxTOP, 5 );
m_bpvBottom = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 );
bSizer3DButtons->Add( m_bpvBottom, 0, wxTOP, 5 );
m_bpUpdate = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1,-1 ), wxBU_AUTODRAW|0 );
m_bpUpdate->SetToolTip( _("Reload board and 3D models") );
bSizer3DButtons->Add( m_bpUpdate, 0, wxTOP, 5 );
bSizermain->Add( bSizer3DButtons, 0, wxALL|wxEXPAND, 5 );
this->SetSizer( bSizermain );
this->Layout();
bSizermain->Fit( this );
// Connect Events
xscale->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelScale ), NULL, this );
xscale->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinXscale->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementScale ), NULL, this );
m_spinXscale->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementScale ), NULL, this );
yscale->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelScale ), NULL, this );
yscale->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinYscale->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementScale ), NULL, this );
m_spinYscale->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementScale ), NULL, this );
zscale->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelScale ), NULL, this );
zscale->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinZscale->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementScale ), NULL, this );
m_spinZscale->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementScale ), NULL, this );
xrot->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelRot ), NULL, this );
xrot->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinXrot->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementRot ), NULL, this );
m_spinXrot->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementRot ), NULL, this );
yrot->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelRot ), NULL, this );
yrot->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinYrot->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementRot ), NULL, this );
m_spinYrot->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementRot ), NULL, this );
zrot->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelRot ), NULL, this );
zrot->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinZrot->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementRot ), NULL, this );
m_spinZrot->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementRot ), NULL, this );
xoff->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelOffset ), NULL, this );
xoff->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinXoffset->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementOffset ), NULL, this );
m_spinXoffset->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementOffset ), NULL, this );
yoff->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelOffset ), NULL, this );
yoff->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinYoffset->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementOffset ), NULL, this );
m_spinYoffset->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementOffset ), NULL, this );
zoff->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelOffset ), NULL, this );
zoff->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinZoffset->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementOffset ), NULL, this );
m_spinZoffset->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementOffset ), NULL, this );
m_bpvISO->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DISO ), NULL, this );
m_bpvLeft->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DLeft ), NULL, this );
m_bpvRight->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DRight ), NULL, this );
m_bpvFront->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DFront ), NULL, this );
m_bpvBack->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DBack ), NULL, this );
m_bpvTop->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DTop ), NULL, this );
m_bpvBottom->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DBottom ), NULL, this );
m_bpUpdate->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DUpdate ), NULL, this );
}
PANEL_PREV_3D_BASE::~PANEL_PREV_3D_BASE()
{
// Disconnect Events
xscale->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelScale ), NULL, this );
xscale->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinXscale->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementScale ), NULL, this );
m_spinXscale->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementScale ), NULL, this );
yscale->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelScale ), NULL, this );
yscale->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinYscale->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementScale ), NULL, this );
m_spinYscale->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementScale ), NULL, this );
zscale->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelScale ), NULL, this );
zscale->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinZscale->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementScale ), NULL, this );
m_spinZscale->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementScale ), NULL, this );
xrot->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelRot ), NULL, this );
xrot->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinXrot->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementRot ), NULL, this );
m_spinXrot->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementRot ), NULL, this );
yrot->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelRot ), NULL, this );
yrot->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinYrot->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementRot ), NULL, this );
m_spinYrot->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementRot ), NULL, this );
zrot->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelRot ), NULL, this );
zrot->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinZrot->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementRot ), NULL, this );
m_spinZrot->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementRot ), NULL, this );
xoff->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelOffset ), NULL, this );
xoff->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinXoffset->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementOffset ), NULL, this );
m_spinXoffset->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementOffset ), NULL, this );
yoff->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelOffset ), NULL, this );
yoff->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinYoffset->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementOffset ), NULL, this );
m_spinYoffset->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementOffset ), NULL, this );
zoff->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREV_3D_BASE::onMouseWheelOffset ), NULL, this );
zoff->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinZoffset->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementOffset ), NULL, this );
m_spinZoffset->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementOffset ), NULL, this );
m_bpvISO->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DISO ), NULL, this );
m_bpvLeft->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DLeft ), NULL, this );
m_bpvRight->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DRight ), NULL, this );
m_bpvFront->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DFront ), NULL, this );
m_bpvBack->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DBack ), NULL, this );
m_bpvTop->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DTop ), NULL, this );
m_bpvBottom->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DBottom ), NULL, this );
m_bpUpdate->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DUpdate ), NULL, this );
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,105 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.9.0 Nov 1 2020)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#pragma once
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/textctrl.h>
#include <wx/spinbutt.h>
#include <wx/sizer.h>
#include <wx/statbox.h>
#include <wx/bmpbuttn.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/button.h>
#include <wx/panel.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class PANEL_PREV_3D_BASE
///////////////////////////////////////////////////////////////////////////////
class PANEL_PREV_3D_BASE : public wxPanel
{
private:
protected:
wxStaticText* m_staticText1;
wxTextCtrl* xscale;
wxSpinButton* m_spinXscale;
wxStaticText* m_staticText2;
wxTextCtrl* yscale;
wxSpinButton* m_spinYscale;
wxStaticText* m_staticText3;
wxTextCtrl* zscale;
wxSpinButton* m_spinZscale;
wxStaticText* m_staticText11;
wxTextCtrl* xrot;
wxSpinButton* m_spinXrot;
wxStaticText* m_staticText21;
wxTextCtrl* yrot;
wxSpinButton* m_spinYrot;
wxStaticText* m_staticText31;
wxTextCtrl* zrot;
wxSpinButton* m_spinZrot;
wxStaticText* m_staticText12;
wxTextCtrl* xoff;
wxSpinButton* m_spinXoffset;
wxStaticText* m_staticText22;
wxSpinButton* m_spinYoffset;
wxStaticText* m_staticText32;
wxTextCtrl* zoff;
wxSpinButton* m_spinZoffset;
wxBoxSizer* m_SizerPanelView;
wxBitmapButton* m_bpvISO;
wxBitmapButton* m_bpvLeft;
wxBitmapButton* m_bpvRight;
wxBitmapButton* m_bpvFront;
wxBitmapButton* m_bpvBack;
wxBitmapButton* m_bpvTop;
wxBitmapButton* m_bpvBottom;
wxBitmapButton* m_bpUpdate;
// Virtual event handlers, overide them in your derived class
virtual void onMouseWheelScale( wxMouseEvent& event ) { event.Skip(); }
virtual void updateOrientation( wxCommandEvent& event ) { event.Skip(); }
virtual void onDecrementScale( wxSpinEvent& event ) { event.Skip(); }
virtual void onIncrementScale( wxSpinEvent& event ) { event.Skip(); }
virtual void onMouseWheelRot( wxMouseEvent& event ) { event.Skip(); }
virtual void onDecrementRot( wxSpinEvent& event ) { event.Skip(); }
virtual void onIncrementRot( wxSpinEvent& event ) { event.Skip(); }
virtual void onMouseWheelOffset( wxMouseEvent& event ) { event.Skip(); }
virtual void onDecrementOffset( wxSpinEvent& event ) { event.Skip(); }
virtual void onIncrementOffset( wxSpinEvent& event ) { event.Skip(); }
virtual void View3DISO( wxCommandEvent& event ) { event.Skip(); }
virtual void View3DLeft( wxCommandEvent& event ) { event.Skip(); }
virtual void View3DRight( wxCommandEvent& event ) { event.Skip(); }
virtual void View3DFront( wxCommandEvent& event ) { event.Skip(); }
virtual void View3DBack( wxCommandEvent& event ) { event.Skip(); }
virtual void View3DTop( wxCommandEvent& event ) { event.Skip(); }
virtual void View3DBottom( wxCommandEvent& event ) { event.Skip(); }
virtual void View3DUpdate( wxCommandEvent& event ) { event.Skip(); }
public:
wxTextCtrl* yoff;
PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
~PANEL_PREV_3D_BASE();
};
@@ -0,0 +1,404 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2015-2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file panel_prev_model.cpp
*/
#include "panel_prev_model.h"
#include <3d_canvas/eda_3d_canvas.h>
#include <common_ogl/cogl_att_list.h>
#include <class_board.h>
#include <base_units.h>
#include <bitmaps.h>
#include <class_drawpanel.h>
#include <dpi_scaling.h>
#include <pgm_base.h>
#include <project.h>
PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, MODULE* aModule,
std::vector<MODULE_3D_SETTINGS> *aParentModelList ) :
PANEL_PREV_3D_BASE( aParent, wxID_ANY )
{
m_userUnits = aFrame->GetUserUnits();
initPanel();
// Initialize the color settings to draw the board and the footprint
m_dummyBoard->SetColorsSettings( &aFrame->Settings().Colors() );
m_parentModelList = aParentModelList;
m_dummyModule = new MODULE( *aModule );
m_dummyBoard->Add( m_dummyModule );
// Set 3d viewer configuration for preview
m_settings3Dviewer = new CINFO3D_VISU();
// Create the 3D canvas
m_previewPane = new EDA_3D_CANVAS( this, COGL_ATT_LIST::GetAttributesList( true ),
m_dummyBoard, *m_settings3Dviewer,
aFrame->Prj().Get3DCacheManager() );
loadCommonSettings();
m_SizerPanelView->Add( m_previewPane, 1, wxEXPAND, 5 );
}
PANEL_PREV_3D::~PANEL_PREV_3D()
{
delete m_settings3Dviewer;
delete m_dummyBoard;
delete m_previewPane;
}
void PANEL_PREV_3D::initPanel()
{
m_dummyBoard = new BOARD();
m_selected = -1;
// Set the bitmap of 3D view buttons:
m_bpvTop->SetBitmap( KiBitmap( axis3d_top_xpm ) );
m_bpvFront->SetBitmap( KiBitmap( axis3d_front_xpm ) );
m_bpvBack->SetBitmap( KiBitmap( axis3d_back_xpm ) );
m_bpvLeft->SetBitmap( KiBitmap( axis3d_left_xpm ) );
m_bpvRight->SetBitmap( KiBitmap( axis3d_right_xpm ) );
m_bpvBottom->SetBitmap( KiBitmap( axis3d_bottom_xpm ) );
m_bpvISO->SetBitmap( KiBitmap( ortho_xpm ) );
m_bpUpdate->SetBitmap( KiBitmap( reload_xpm ) );
// Set the min and max values of spin buttons (mandatory on Linux)
// They are not used, so they are set to min and max 32 bits int values
// (the min and max values supported by a wxSpinButton)
// It avoids blocking the up or down arrows when reaching this limit after
// a few clicks.
wxSpinButton* spinButtonList[] =
{
m_spinXscale, m_spinYscale, m_spinZscale,
m_spinXrot, m_spinYrot, m_spinZrot,
m_spinXoffset,m_spinYoffset, m_spinZoffset
};
for( int ii = 0; ii < 9; ii++ )
spinButtonList[ii]->SetRange( INT_MIN, INT_MAX );
}
void PANEL_PREV_3D::loadCommonSettings()
{
wxCHECK_RET( m_previewPane, "Cannot load settings to null canvas" );
wxConfigBase& cmnCfg = *Pgm().CommonSettings();
{
const DPI_SCALING dpi{ &cmnCfg, this };
m_previewPane->SetScaleFactor( dpi.GetScaleFactor() );
}
{
bool option;
cmnCfg.Read( ENBL_MOUSEWHEEL_PAN_KEY, &option, false );
m_settings3Dviewer->SetFlag( FL_MOUSEWHEEL_PANNING, option );
}
}
/**
* @brief rotationFromString
* Ensure -MAX_ROTATION <= rotation <= MAX_ROTATION
* aRotation will be normalized between -MAX_ROTATION and MAX_ROTATION
*/
static double rotationFromString( const wxString& aValue )
{
double rotation = DoubleValueFromString( DEGREES, aValue ) / 10.0;
if( rotation > MAX_ROTATION )
{
int n = rotation / MAX_ROTATION;
rotation -= MAX_ROTATION * n;
}
else if( rotation < -MAX_ROTATION )
{
int n = -rotation / MAX_ROTATION;
rotation += MAX_ROTATION * n;
}
return rotation;
}
wxString PANEL_PREV_3D::formatScaleValue( double aValue )
{
return wxString::Format( "%.4f", aValue );
}
wxString PANEL_PREV_3D::formatRotationValue( double aValue )
{
return wxString::Format( "%.2f %s", aValue, GetAbbreviatedUnitsLabel( DEGREES ) );
}
wxString PANEL_PREV_3D::formatOffsetValue( double aValue )
{
// Convert from internal units (mm) to user units
if( m_userUnits == INCHES )
aValue /= 25.4f;
return wxString::Format( "%.4f %s", aValue, GetAbbreviatedUnitsLabel( m_userUnits ) );
}
void PANEL_PREV_3D::SetSelectedModel( int idx )
{
if( m_parentModelList && idx >= 0 && idx < (int) m_parentModelList->size() )
{
m_selected = idx;
const MODULE_3D_SETTINGS& modelInfo = m_parentModelList->at( (unsigned) m_selected );
// Use ChangeValue() instead of SetValue(). It's not the user making the change, so we
// don't want to generate wxEVT_GRID_CELL_CHANGED events.
xscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.x ) );
yscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.y ) );
zscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.z ) );
xrot->ChangeValue( formatRotationValue( modelInfo.m_Rotation.x ) );
yrot->ChangeValue( formatRotationValue( modelInfo.m_Rotation.y ) );
zrot->ChangeValue( formatRotationValue( modelInfo.m_Rotation.z ) );
xoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.x ) );
yoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.y ) );
zoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.z ) );
}
else
{
m_selected = -1;
xscale->ChangeValue( wxEmptyString );
yscale->ChangeValue( wxEmptyString );
zscale->ChangeValue( wxEmptyString );
xrot->ChangeValue( wxEmptyString );
yrot->ChangeValue( wxEmptyString );
zrot->ChangeValue( wxEmptyString );
xoff->ChangeValue( wxEmptyString );
yoff->ChangeValue( wxEmptyString );
zoff->ChangeValue( wxEmptyString );
}
}
void PANEL_PREV_3D::updateOrientation( wxCommandEvent &event )
{
if( m_parentModelList && m_selected >= 0 && m_selected < (int) m_parentModelList->size() )
{
// Write settings back to the parent
MODULE_3D_SETTINGS* modelInfo = &m_parentModelList->at( (unsigned) m_selected );
modelInfo->m_Scale.x = DoubleValueFromString( UNSCALED_UNITS, xscale->GetValue() );
modelInfo->m_Scale.y = DoubleValueFromString( UNSCALED_UNITS, yscale->GetValue() );
modelInfo->m_Scale.z = DoubleValueFromString( UNSCALED_UNITS, zscale->GetValue() );
modelInfo->m_Rotation.x = rotationFromString( xrot->GetValue() );
modelInfo->m_Rotation.y = rotationFromString( yrot->GetValue() );
modelInfo->m_Rotation.z = rotationFromString( zrot->GetValue() );
modelInfo->m_Offset.x = DoubleValueFromString( m_userUnits, xoff->GetValue() ) / IU_PER_MM;
modelInfo->m_Offset.y = DoubleValueFromString( m_userUnits, yoff->GetValue() ) / IU_PER_MM;
modelInfo->m_Offset.z = DoubleValueFromString( m_userUnits, zoff->GetValue() ) / IU_PER_MM;
// Update the dummy module for the preview
UpdateDummyModule( false );
}
}
void PANEL_PREV_3D::doIncrementScale( wxSpinEvent& event, double aSign )
{
wxSpinButton* spinCtrl = (wxSpinButton*) event.GetEventObject();
wxTextCtrl * textCtrl = xscale;
if( spinCtrl == m_spinYscale )
textCtrl = yscale;
else if( spinCtrl == m_spinZscale )
textCtrl = zscale;
double curr_value = DoubleValueFromString( UNSCALED_UNITS, textCtrl->GetValue() );
curr_value += ( SCALE_INCREMENT * aSign );
curr_value = std::max( 1/MAX_SCALE, curr_value );
curr_value = std::min( curr_value, MAX_SCALE );
textCtrl->SetValue( formatScaleValue( curr_value ) );
}
void PANEL_PREV_3D::doIncrementRotation( wxSpinEvent& aEvent, double aSign )
{
wxSpinButton* spinCtrl = (wxSpinButton*) aEvent.GetEventObject();
wxTextCtrl* textCtrl = xrot;
if( spinCtrl == m_spinYrot )
textCtrl = yrot;
else if( spinCtrl == m_spinZrot )
textCtrl = zrot;
double curr_value = DoubleValueFromString( DEGREES, textCtrl->GetValue() ) / 10.0;
curr_value += ( ROTATION_INCREMENT * aSign );
curr_value = std::max( -MAX_ROTATION, curr_value );
curr_value = std::min( curr_value, MAX_ROTATION );
textCtrl->SetValue( formatRotationValue( curr_value ) );
}
void PANEL_PREV_3D::doIncrementOffset( wxSpinEvent& event, double aSign )
{
wxSpinButton* spinCtrl = (wxSpinButton*) event.GetEventObject();
wxTextCtrl * textCtrl = xoff;
if( spinCtrl == m_spinYoffset )
textCtrl = yoff;
else if( spinCtrl == m_spinZoffset )
textCtrl = zoff;
double step = OFFSET_INCREMENT_MM;
if( m_userUnits == INCHES )
step = OFFSET_INCREMENT_MIL/1000.0;
double curr_value = DoubleValueFromString( m_userUnits, textCtrl->GetValue() ) / IU_PER_MM;
curr_value += ( step * aSign );
curr_value = std::max( -MAX_OFFSET, curr_value );
curr_value = std::min( curr_value, MAX_OFFSET );
textCtrl->SetValue( formatOffsetValue( curr_value ) );
}
void PANEL_PREV_3D::onMouseWheelScale( wxMouseEvent& event )
{
wxTextCtrl* textCtrl = (wxTextCtrl*) event.GetEventObject();
double step = SCALE_INCREMENT;
if( event.ShiftDown( ) )
step = SCALE_INCREMENT_FINE;
if( event.GetWheelRotation() >= 0 )
step = -step;
double curr_value = DoubleValueFromString( UNSCALED_UNITS, textCtrl->GetValue() );
curr_value += step;
curr_value = std::max( 1/MAX_SCALE, curr_value );
curr_value = std::min( curr_value, MAX_SCALE );
textCtrl->SetValue( formatScaleValue( curr_value ) );
}
void PANEL_PREV_3D::onMouseWheelRot( wxMouseEvent& event )
{
wxTextCtrl* textCtrl = (wxTextCtrl*) event.GetEventObject();
double step = ROTATION_INCREMENT_WHEEL;
if( event.ShiftDown( ) )
step = ROTATION_INCREMENT_WHEEL_FINE;
if( event.GetWheelRotation() >= 0 )
step = -step;
double curr_value = DoubleValueFromString( DEGREES, textCtrl->GetValue() ) / 10.0;
curr_value += step;
curr_value = std::max( -MAX_ROTATION, curr_value );
curr_value = std::min( curr_value, MAX_ROTATION );
textCtrl->SetValue( formatRotationValue( curr_value ) );
}
void PANEL_PREV_3D::onMouseWheelOffset( wxMouseEvent& event )
{
wxTextCtrl* textCtrl = (wxTextCtrl*) event.GetEventObject();
double step = OFFSET_INCREMENT_MM;
if( event.ShiftDown( ) )
step = OFFSET_INCREMENT_MM_FINE;
if( m_userUnits == INCHES )
{
step = OFFSET_INCREMENT_MIL/1000.0;
if( event.ShiftDown( ) )
step = OFFSET_INCREMENT_MIL_FINE/1000.0;
}
if( event.GetWheelRotation() >= 0 )
step = -step;
double curr_value = DoubleValueFromString( m_userUnits, textCtrl->GetValue() ) / IU_PER_MM;
curr_value += step;
curr_value = std::max( -MAX_OFFSET, curr_value );
curr_value = std::min( curr_value, MAX_OFFSET );
textCtrl->SetValue( formatOffsetValue( curr_value ) );
}
void PANEL_PREV_3D::UpdateDummyModule( bool aReloadRequired )
{
m_dummyModule->Models().clear();
for( size_t i = 0; i < m_parentModelList->size(); ++i )
{
if( m_parentModelList->at( i ).m_Preview )
{
m_dummyModule->Models().insert( m_dummyModule->Models().end(),
m_parentModelList->at( i ) );
}
}
if( aReloadRequired )
m_previewPane->ReloadRequest();
m_previewPane->Request_refresh();
}
@@ -0,0 +1,200 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file panel_prev_model.h
* @brief Defines a panel which is to be added to a wxFileDialog via
* SetExtraControl();
* The panel shows a preview of the module being edited and provides controls
* to set the offset/rotation/scale of each model 3d shape as per KiCad's
* current behavior. The panel may also be used in the 3D configuration dialog
* to tune the positioning of the models without invoking a file selector dialog.
*/
#ifndef PANEL_PREV_MODEL_H
#define PANEL_PREV_MODEL_H
#include "panel_prev_3d_base.h"
#include <vector>
#include <3d_canvas/eda_3d_canvas.h>
// Define min and max parameter values
#define MAX_SCALE 10000.0
#define MAX_ROTATION 180.0
#define MAX_OFFSET 1000.0
#define SCALE_INCREMENT_FINE 0.02
#define SCALE_INCREMENT 0.1
#define ROTATION_INCREMENT 5 // in degrees, for spin button command
#define ROTATION_INCREMENT_WHEEL 15 // in degrees, for mouse wheel command
#define ROTATION_INCREMENT_WHEEL_FINE 1 // in degrees, for mouse wheel command
#define OFFSET_INCREMENT_MM 0.5
#define OFFSET_INCREMENT_MM_FINE 0.1
#define OFFSET_INCREMENT_MIL 25.0
#define OFFSET_INCREMENT_MIL_FINE 5.0
// Declared classes to create pointers
class S3D_CACHE;
class FILENAME_RESOLVER;
class BOARD;
class CINFO3D_VISU;
class MODULE;
class COLORS_DESIGN_SETTINGS;
class PANEL_PREV_3D: public PANEL_PREV_3D_BASE
{
public:
PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, MODULE* aModule,
std::vector<MODULE_3D_SETTINGS> *aParentModelList );
~PANEL_PREV_3D();
private:
EDA_3D_CANVAS* m_previewPane;
CINFO3D_VISU* m_settings3Dviewer;
BOARD* m_dummyBoard;
MODULE* m_dummyModule;
std::vector<MODULE_3D_SETTINGS>* m_parentModelList;
int m_selected; /// Index into m_parentInfoList
EDA_UNITS_T m_userUnits;
// Methods of the class
private:
void initPanel();
/**
* Load 3D relevant settings from the user configuration
*/
void loadCommonSettings();
/**
* @brief updateOrientation - it will receive the events from editing the fields
* @param event
*/
void updateOrientation( wxCommandEvent &event ) override;
void onMouseWheelScale( wxMouseEvent& event ) override;
void onMouseWheelRot( wxMouseEvent& event ) override;
void onMouseWheelOffset( wxMouseEvent& event ) override;
void onIncrementRot( wxSpinEvent& event ) override
{
doIncrementRotation( event, 1.0 );
}
void onDecrementRot( wxSpinEvent& event ) override
{
doIncrementRotation( event, -1.0 );
}
void onIncrementScale( wxSpinEvent& event ) override
{
doIncrementScale( event, 1.0 );
}
void onDecrementScale( wxSpinEvent& event ) override
{
doIncrementScale( event, -1.0 );
}
void onIncrementOffset( wxSpinEvent& event ) override
{
doIncrementOffset( event, 1.0 );
}
void onDecrementOffset( wxSpinEvent& event ) override
{
doIncrementOffset( event, -1.0 );
}
void doIncrementScale( wxSpinEvent& aEvent, double aSign );
void doIncrementRotation( wxSpinEvent& aEvent, double aSign );
void doIncrementOffset( wxSpinEvent& aEvent, double aSign );
wxString formatScaleValue( double aValue );
wxString formatRotationValue( double aValue );
wxString formatOffsetValue( double aValue );
void View3DISO( wxCommandEvent& event ) override
{
m_settings3Dviewer->CameraGet().ToggleProjection();
m_previewPane->Refresh();
}
void View3DLeft( wxCommandEvent& event ) override
{
m_previewPane->SetView3D( GR_KB_SHIFT + 'X' );
}
void View3DFront( wxCommandEvent& event ) override
{
m_previewPane->SetView3D( 'Y' );
}
void View3DTop( wxCommandEvent& event ) override
{
m_previewPane->SetView3D( 'Z' );
}
void View3DUpdate( wxCommandEvent& event ) override
{
m_previewPane->ReloadRequest();
m_previewPane->Refresh();
}
void View3DRight( wxCommandEvent& event ) override
{
m_previewPane->SetView3D( 'X' );
}
void View3DBack( wxCommandEvent& event ) override
{
m_previewPane->SetView3D( GR_KB_SHIFT + 'Y' );
}
void View3DBottom( wxCommandEvent& event ) override
{
m_previewPane->SetView3D( GR_KB_SHIFT + 'Z' );
}
public:
/**
* @brief SetModelDataIdx - Sets the currently selected index in the model list so that
* the scale/rotation/offset controls can be updated.
*/
void SetSelectedModel( int idx );
/**
* @brief UpdateModelInfoList - copy shapes from the current shape list which are flagged
* for preview to the copy of module that is on the preview dummy board
*/
void UpdateDummyModule( bool aRelaodRequired = true );
};
#endif // PANEL_PREV_MODEL_H
+1 -6
View File
@@ -91,7 +91,7 @@ endif()
unset( S3DSG_VERSION_FILE CACHE )
# Define a flag to expose the appropriate EXPORT macro at build time
target_compile_definitions( kicad_3dsg PRIVATE COMPILE_SGLIB )
target_compile_definitions( kicad_3dsg PRIVATE -DCOMPILE_SGLIB )
target_link_libraries( kicad_3dsg ${wxWidgets_LIBRARIES} )
@@ -104,8 +104,3 @@ install( TARGETS
LIBRARY DESTINATION ${KICAD_LIB}
COMPONENT binary
)
if( KICAD_WIN32_INSTALL_PDBS )
# Get the PDBs to copy over for MSVC
install(FILES $<TARGET_PDB_FILE:kicad_3dsg> DESTINATION ${KICAD_BIN})
endif()
+231 -87
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -25,7 +24,6 @@
#include <iostream>
#include <sstream>
#include <fstream>
#include <memory>
#include <wx/filename.h>
#include <wx/log.h>
#include "plugins/3dapi/ifsg_api.h"
@@ -38,6 +36,10 @@
#include "3d_cache/sg/sg_helpers.h"
#ifdef DEBUG
static char BadNode[] = " * [BUG] NULL pointer passed for aNode\n";
#endif
// version format of the cache file
#define SG_VERSION_TAG "VERSION:2"
@@ -71,13 +73,15 @@ static void formatMaterial( SMATERIAL& mat, SGAPPEARANCE const* app )
mat.m_Shininess = app->shininess;
mat.m_Transparency = app->transparency;
return;
}
bool S3D::WriteVRML( const char* filename, bool overwrite, SGNODE* aTopNode,
bool reuse, bool renameNodes )
bool reuse, bool renameNodes )
{
if( nullptr == filename || filename[0] == 0 )
if( NULL == filename || filename[0] == 0 )
return false;
wxString ofile = wxString::FromUTF8Unchecked( filename );
@@ -92,19 +96,46 @@ bool S3D::WriteVRML( const char* filename, bool overwrite, SGNODE* aTopNode,
return false;
}
wxCHECK( aTopNode && aTopNode->GetNodeType() == S3D::SGTYPE_TRANSFORM, false );
if( NULL == aTopNode )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL pointer passed for aTopNode";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
if( S3D::SGTYPE_TRANSFORM != aTopNode->GetNodeType() )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] aTopNode is not a SCENEGRAPH object";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
OPEN_OSTREAM( op, filename );
if( op.fail() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] failed to open file '%s'" ),
__FILE__, __FUNCTION__, __LINE__, filename );
wxString errmsg;
errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
errmsg << " * [INFO] " << "failed to open file" << " '" << filename << "'";
wxLogTrace( MASK_3D_SG, errmsg );
return false;
}
op.imbue( std::locale::classic() );
op.imbue( std::locale( "C" ) );
op << "#VRML V2.0 utf8\n";
if( renameNodes )
@@ -123,8 +154,10 @@ bool S3D::WriteVRML( const char* filename, bool overwrite, SGNODE* aTopNode,
CLOSE_STREAM( op );
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] problems encountered writing file '%s'" ),
__FILE__, __FUNCTION__, __LINE__, filename );
wxString errmsg;
errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
errmsg << " * [INFO] " << "problems encountered writing file" << " '" << filename << "'";
wxLogTrace( MASK_3D_SG, errmsg );
return false;
}
@@ -132,44 +165,102 @@ bool S3D::WriteVRML( const char* filename, bool overwrite, SGNODE* aTopNode,
void S3D::ResetNodeIndex( SGNODE* aNode )
{
wxCHECK( aNode, /* void */ );
if( NULL == aNode )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadNode;
wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
} while( 0 );
#endif
return;
}
aNode->ResetNodeIndex();
return;
}
void S3D::RenameNodes( SGNODE* aNode )
{
wxCHECK( aNode, /* void */ );
if( NULL == aNode )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadNode;
wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
} while( 0 );
#endif
return;
}
aNode->ReNameNodes();
return;
}
void S3D::DestroyNode( SGNODE* aNode ) noexcept
void S3D::DestroyNode( SGNODE* aNode )
{
wxCHECK( aNode, /* void */ );
if( NULL == aNode )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadNode;
wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
} while( 0 );
#endif
return;
}
delete aNode;
return;
}
bool S3D::WriteCache( const char* aFileName, bool overwrite, SGNODE* aNode,
const char* aPluginInfo )
const char* aPluginInfo )
{
if( nullptr == aFileName || aFileName[0] == 0 )
if( NULL == aFileName || aFileName[0] == 0 )
return false;
wxString ofile = wxString::FromUTF8Unchecked( aFileName );
wxCHECK( aNode, false );
if( NULL == aNode )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadNode;
wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
if( wxFileName::Exists( ofile ) )
{
if( !overwrite )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] file exists not overwriting '%s'" ),
__FILE__, __FUNCTION__, __LINE__, aFileName );
wxString errmsg;
errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
errmsg << " * [INFO] " << "file exists; not overwriting" << " '";
errmsg << aFileName << "'";
wxLogTrace( MASK_3D_SG, errmsg );
return false;
}
@@ -177,9 +268,11 @@ bool S3D::WriteCache( const char* aFileName, bool overwrite, SGNODE* aNode,
// make sure we make no attempt to write a directory
if( !wxFileName::FileExists( aFileName ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] specified path is a directory '%s'" ),
__FILE__, __FUNCTION__, __LINE__, aFileName );
wxString errmsg;
errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
errmsg << " * [INFO] " << "specified path is a directory" << " '";
errmsg << aFileName << "'";
wxLogTrace( MASK_3D_SG, errmsg );
return false;
}
}
@@ -188,27 +281,34 @@ bool S3D::WriteCache( const char* aFileName, bool overwrite, SGNODE* aNode,
if( output.fail() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] failed to open file '%s'" ),
__FILE__, __FUNCTION__, __LINE__, aFileName );
wxString errmsg;
errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
errmsg << " * [INFO] " << "failed to open file" << " '" << aFileName << "'";
wxLogTrace( MASK_3D_SG, errmsg );
return false;
}
output << "(" << SG_VERSION_TAG << ")";
if( nullptr != aPluginInfo && aPluginInfo[0] != 0 )
if( NULL != aPluginInfo && aPluginInfo[0] != 0 )
output << "(" << aPluginInfo << ")";
else
output << "(INTERNAL:0.0.0.0)";
bool rval = aNode->WriteCache( output, nullptr );
bool rval = aNode->WriteCache( output, NULL );
CLOSE_STREAM( output );
if( !rval )
{
wxLogTrace( MASK_3D_SG,
wxT( "%s:%s:%d * [INFO] problems encountered writing cache file '%s'" ),
__FILE__, __FUNCTION__, __LINE__, aFileName );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] problems encountered writing cache file '";
ostr << aFileName << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
// delete the defective file
wxRemoveFile( ofile );
@@ -219,31 +319,53 @@ bool S3D::WriteCache( const char* aFileName, bool overwrite, SGNODE* aNode,
SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
bool (*aTagCheck)( const char*, void* ) )
bool (*aTagCheck)( const char*, void* ) )
{
if( nullptr == aFileName || aFileName[0] == 0 )
return nullptr;
if( NULL == aFileName || aFileName[0] == 0 )
return NULL;
wxString ofile = wxString::FromUTF8Unchecked( aFileName );
if( !wxFileName::FileExists( aFileName ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] no such file '%s'" ),
__FILE__, __FUNCTION__, __LINE__, aFileName );
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
wxString errmsg = _( "no such file" );
ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
ostr << aFileName << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
return nullptr;
return NULL;
}
std::unique_ptr<SGNODE> np = std::make_unique<SCENEGRAPH>( nullptr );
SGNODE* np = new SCENEGRAPH( NULL );
if( NULL == np )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] failed to instantiate SCENEGRAPH";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return NULL;
}
OPEN_ISTREAM( file, aFileName );
if( file.fail() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] failed to open file '%s'" ),
__FILE__, __FUNCTION__, __LINE__, aFileName );
return nullptr;
delete np;
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
wxString errmsg = _( "failed to open file" );
ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
ostr << aFileName << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
return NULL;
}
// from SG_VERSION_TAG 1, read the version tag; if it's not the expected tag
@@ -256,13 +378,18 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
if( '(' != schar )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; missing left parenthesis"
" at position '%d'" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<int>( file.tellg() ) );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; missing left parenthesis at position ";
ostr << file.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
CLOSE_STREAM( file );
return nullptr;
return NULL;
}
file.get( schar );
@@ -276,7 +403,7 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
if( name.compare( SG_VERSION_TAG ) )
{
CLOSE_STREAM( file );
return nullptr;
return NULL;
}
} while( 0 );
@@ -291,13 +418,18 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
if( '(' != schar )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; missing left parenthesis"
" at position '%d'" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<int>( file.tellg() ) );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; missing left parenthesis at position ";
ostr << file.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
CLOSE_STREAM( file );
return nullptr;
return NULL;
}
file.get( schar );
@@ -309,39 +441,40 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
}
// check the plugin tag
if( nullptr != aTagCheck && nullptr != aPluginMgr
&& !aTagCheck( name.c_str(), aPluginMgr ) )
if( NULL != aTagCheck && NULL != aPluginMgr && !aTagCheck( name.c_str(), aPluginMgr ) )
{
CLOSE_STREAM( file );
return nullptr;
return NULL;
}
} while( 0 );
bool rval = np->ReadCache( file, nullptr );
bool rval = np->ReadCache( file, NULL );
CLOSE_STREAM( file );
if( !rval )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] problems encountered reading cache file "
"'%s'" ),
__FILE__, __FUNCTION__, __LINE__,
aFileName );
return nullptr;
delete np;
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
wxString errmsg = "problems encountered reading cache file";
ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
ostr << aFileName << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
return NULL;
}
return np.release();
return np;
}
S3DMODEL* S3D::GetModel( SCENEGRAPH* aNode )
{
if( nullptr == aNode )
return nullptr;
if( NULL == aNode )
return NULL;
if( aNode->GetNodeType() != S3D::SGTYPE_TRANSFORM )
return nullptr;
return NULL;
S3D::MATLIST materials;
std::vector< SMESH > meshes;
@@ -351,20 +484,20 @@ S3DMODEL* S3D::GetModel( SCENEGRAPH* aNode )
// gray in hopes that it may help highlight faulty models; this color is
// also typical of MCAD applications. When a model has no associated
// material color it shall be assigned the index 0.
SGAPPEARANCE app( nullptr );
app.ambient = SGCOLOR( 0.6f, 0.6f, 0.6f );
app.diffuse = SGCOLOR( 0.6f, 0.6f, 0.6f );
SGAPPEARANCE app( NULL );
app.ambient = SGCOLOR( 0.6, 0.6, 0.6 );
app.diffuse = SGCOLOR( 0.6, 0.6, 0.6 );
app.specular = app.diffuse;
app.shininess = 0.05f;
app.transparency = 0.0f;
app.shininess = 0.05;
app.transparency = 0.0;
materials.matorder.push_back( &app );
materials.matmap.emplace( &app, 0 );
materials.matmap.insert( std::pair< SGAPPEARANCE const*, int >( &app, 0 ) );
if( aNode->Prepare( nullptr, materials, meshes ) )
if( aNode->Prepare( NULL, materials, meshes ) )
{
if( meshes.empty() )
return nullptr;
return NULL;
S3DMODEL* model = S3D::New3DModel();
@@ -396,31 +529,35 @@ S3DMODEL* S3D::GetModel( SCENEGRAPH* aNode )
for( size_t i = 0; i < j; ++i )
S3D::Free3DMesh( meshes[i] );
return nullptr;
return NULL;
}
void S3D::Destroy3DModel( S3DMODEL** aModel )
{
if( nullptr == aModel || nullptr == *aModel )
if( NULL == aModel || NULL == *aModel )
return;
S3DMODEL* m = *aModel;
S3D::FREE_S3DMODEL( *m );
delete m;
*aModel = nullptr;
*aModel = NULL;
return;
}
void Free3DModel( S3DMODEL& aModel )
{
S3D::FREE_S3DMODEL( aModel );
return;
}
void S3D::Free3DMesh( SMESH& aMesh )
{
S3D::FREE_SMESH( aMesh );
return;
}
@@ -435,17 +572,20 @@ S3DMODEL* S3D::New3DModel( void )
void S3D::Init3DMaterial( SMATERIAL& aMat )
{
S3D::INIT_SMATERIAL( aMat );
return;
}
void S3D::Init3DMesh( SMESH& aMesh )
{
S3D::INIT_SMESH( aMesh );
return;
}
void S3D::GetLibVersion( unsigned char* Major, unsigned char* Minor, unsigned char* Patch,
unsigned char* Revision ) noexcept
void S3D::GetLibVersion( unsigned char* Major, unsigned char* Minor,
unsigned char* Patch, unsigned char* Revision )
{
if( Major )
*Major = KICADSG_VERSION_MAJOR;
@@ -458,6 +598,8 @@ void S3D::GetLibVersion( unsigned char* Major, unsigned char* Minor, unsigned ch
if( Patch )
*Patch = KICADSG_VERSION_PATCH;
return;
}
@@ -476,7 +618,7 @@ SGVECTOR S3D::CalcTriNorm( const SGPOINT& p1, const SGPOINT& p2, const SGPOINT&
// normal
tri = glm::cross( pts[1] - pts[0], pts[2] - pts[0] );
(void)glm::normalize( tri );
glm::normalize( tri );
return SGVECTOR( tri.x, tri.y, tri.z );
}
@@ -484,7 +626,7 @@ SGVECTOR S3D::CalcTriNorm( const SGPOINT& p1, const SGPOINT& p2, const SGPOINT&
S3D::SGTYPES S3D::GetSGNodeType( SGNODE* aNode )
{
if( nullptr == aNode )
if( NULL == aNode )
return SGTYPE_END;
return aNode->GetNodeType();
@@ -493,8 +635,8 @@ S3D::SGTYPES S3D::GetSGNodeType( SGNODE* aNode )
SGNODE* S3D::GetSGNodeParent( SGNODE* aNode )
{
if( nullptr == aNode )
return nullptr;
if( NULL == aNode )
return NULL;
return aNode->GetParent();
}
@@ -502,7 +644,7 @@ SGNODE* S3D::GetSGNodeParent( SGNODE* aNode )
bool S3D::AddSGNodeRef( SGNODE* aParent, SGNODE* aChild )
{
if( nullptr == aParent || nullptr == aChild )
if( NULL == aParent || NULL == aChild )
return false;
return aParent->AddRefNode( aChild );
@@ -511,7 +653,7 @@ bool S3D::AddSGNodeRef( SGNODE* aParent, SGNODE* aChild )
bool S3D::AddSGNodeChild( SGNODE* aParent, SGNODE* aChild )
{
if( nullptr == aParent || nullptr == aChild )
if( NULL == aParent || NULL == aChild )
return false;
return aParent->AddChildNode( aChild );
@@ -520,8 +662,10 @@ bool S3D::AddSGNodeChild( SGNODE* aParent, SGNODE* aChild )
void S3D::AssociateSGNodeWrapper( SGNODE* aObject, SGNODE** aRefPtr )
{
if( nullptr == aObject || nullptr == aRefPtr || aObject != *aRefPtr )
if( NULL == aObject || NULL == aRefPtr || aObject != *aRefPtr )
return;
aObject->AssociateWrapper( aRefPtr );
return;
}
+253 -65
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -30,39 +29,55 @@
#include "3d_cache/sg/sg_appearance.h"
extern char BadObject[];
extern char BadOperand[];
extern char BadParent[];
extern char WrongParent[];
IFSG_APPEARANCE::IFSG_APPEARANCE( bool create )
{
m_node = nullptr;
m_node = NULL;
if( !create )
return ;
m_node = new SGAPPEARANCE( nullptr );
m_node = new SGAPPEARANCE( NULL );
m_node->AssociateWrapper( &m_node );
if( m_node )
m_node->AssociateWrapper( &m_node );
return;
}
IFSG_APPEARANCE::IFSG_APPEARANCE( SGNODE* aParent )
{
m_node = new SGAPPEARANCE( nullptr );
m_node = new SGAPPEARANCE( NULL );
if( !m_node->SetParent( aParent ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( aParent ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -70,28 +85,39 @@ IFSG_APPEARANCE::IFSG_APPEARANCE( IFSG_NODE& aParent )
{
SGNODE* pp = aParent.GetRawPtr();
#ifdef DEBUG
#ifdef DEBUG
if( ! pp )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
BadParent );
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
}
#endif
#endif
m_node = new SGAPPEARANCE( nullptr );
m_node = new SGAPPEARANCE( NULL );
if( !m_node->SetParent( pp ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( pp ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -100,7 +126,7 @@ bool IFSG_APPEARANCE::Attach( SGNODE* aNode )
if( m_node )
m_node->DisassociateWrapper( &m_node );
m_node = nullptr;
m_node = NULL;
if( !aNode )
return false;
@@ -126,13 +152,17 @@ bool IFSG_APPEARANCE::NewNode( SGNODE* aParent )
if( aParent != m_node->GetParent() )
{
wxLogTrace( MASK_3D_SG,
wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGAPPEARANCE" ),
__FILE__, __FUNCTION__, __LINE__,
aParent->GetNodeTypeName( aParent->GetNodeType() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid SGNODE parent (";
ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
ostr << ") to SGAPPEARANCE";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
delete m_node;
m_node = nullptr;
m_node = NULL;
return false;
}
@@ -146,7 +176,17 @@ bool IFSG_APPEARANCE::NewNode( IFSG_NODE& aParent )
{
SGNODE* np = aParent.GetRawPtr();
wxCHECK( np, false );
if( NULL == np )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return NewNode( np );
}
@@ -154,131 +194,279 @@ bool IFSG_APPEARANCE::NewNode( IFSG_NODE& aParent )
bool IFSG_APPEARANCE::SetEmissive( float aRVal, float aGVal, float aBVal )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject << "\n";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGAPPEARANCE*) m_node )->SetEmissive( aRVal, aGVal, aBVal );
return false;
}
return ((SGAPPEARANCE*)m_node)->SetEmissive( aRVal, aGVal, aBVal );
}
bool IFSG_APPEARANCE::SetEmissive( const SGCOLOR* aRGBColor )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject << "\n";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGAPPEARANCE*) m_node )->SetEmissive( aRGBColor );
return false;
}
return ((SGAPPEARANCE*)m_node)->SetEmissive( aRGBColor );
}
bool IFSG_APPEARANCE::SetEmissive( const SGCOLOR& aRGBColor )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGAPPEARANCE*) m_node )->SetEmissive( aRGBColor );
return false;
}
return ((SGAPPEARANCE*)m_node)->SetEmissive( aRGBColor );
}
bool IFSG_APPEARANCE::SetDiffuse( float aRVal, float aGVal, float aBVal )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGAPPEARANCE*) m_node )->SetDiffuse( aRVal, aGVal, aBVal );
return false;
}
return ((SGAPPEARANCE*)m_node)->SetDiffuse( aRVal, aGVal, aBVal );
}
bool IFSG_APPEARANCE::SetDiffuse( const SGCOLOR* aRGBColor )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGAPPEARANCE*) m_node )->SetDiffuse( aRGBColor );
return false;
}
return ((SGAPPEARANCE*)m_node)->SetDiffuse( aRGBColor );
}
bool IFSG_APPEARANCE::SetDiffuse( const SGCOLOR& aRGBColor )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGAPPEARANCE*) m_node )->SetDiffuse( aRGBColor );
return false;
}
return ((SGAPPEARANCE*)m_node)->SetDiffuse( aRGBColor );
}
bool IFSG_APPEARANCE::SetSpecular( float aRVal, float aGVal, float aBVal )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGAPPEARANCE*) m_node )->SetSpecular( aRVal, aGVal, aBVal );
return false;
}
return ((SGAPPEARANCE*)m_node)->SetSpecular( aRVal, aGVal, aBVal );
}
bool IFSG_APPEARANCE::SetSpecular( const SGCOLOR* aRGBColor )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGAPPEARANCE*) m_node )->SetSpecular( aRGBColor );
return false;
}
return ((SGAPPEARANCE*)m_node)->SetSpecular( aRGBColor );
}
bool IFSG_APPEARANCE::SetSpecular( const SGCOLOR& aRGBColor )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGAPPEARANCE*) m_node )->SetSpecular( aRGBColor );
return false;
}
return ((SGAPPEARANCE*)m_node)->SetSpecular( aRGBColor );
}
bool IFSG_APPEARANCE::SetAmbient( float aRVal, float aGVal, float aBVal )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGAPPEARANCE*) m_node )->SetAmbient( aRVal, aGVal, aBVal );
return false;
}
return ((SGAPPEARANCE*)m_node)->SetAmbient( aRVal, aGVal, aBVal );
}
bool IFSG_APPEARANCE::SetAmbient( const SGCOLOR* aRGBColor )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGAPPEARANCE*) m_node )->SetAmbient( aRGBColor );
return false;
}
return ((SGAPPEARANCE*)m_node)->SetAmbient( aRGBColor );
}
bool IFSG_APPEARANCE::SetAmbient( const SGCOLOR& aRGBColor )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGAPPEARANCE*) m_node )->SetAmbient( aRGBColor );
return false;
}
return ((SGAPPEARANCE*)m_node)->SetAmbient( aRGBColor );
}
bool IFSG_APPEARANCE::SetShininess( float aShininess ) noexcept
bool IFSG_APPEARANCE::SetShininess( float aShininess )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( aShininess < 0 || aShininess > 1.0 )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] shininess out of range [0..1]" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] shininess out of range [0..1]";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
( (SGAPPEARANCE*) m_node )->shininess = aShininess;
((SGAPPEARANCE*)m_node)->shininess = aShininess;
return true;
}
bool IFSG_APPEARANCE::SetTransparency( float aTransparency ) noexcept
bool IFSG_APPEARANCE::SetTransparency( float aTransparency )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( aTransparency < 0 || aTransparency > 1.0 )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] transparency out of range [0..1]" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] transparency out of range [0..1]";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
( (SGAPPEARANCE*) m_node )->transparency = aTransparency;
((SGAPPEARANCE*)m_node)->transparency = aTransparency;
return true;
}
+118 -40
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -30,38 +29,52 @@
#include "3d_cache/sg/sg_colors.h"
extern char BadObject[];
extern char BadParent[];
extern char WrongParent[];
IFSG_COLORS::IFSG_COLORS( bool create )
{
m_node = nullptr;
m_node = NULL;
if( !create )
return;
return ;
m_node = new SGCOLORS( nullptr );
m_node = new SGCOLORS( NULL );
m_node->AssociateWrapper( &m_node );
if( m_node )
m_node->AssociateWrapper( &m_node );
return;
}
IFSG_COLORS::IFSG_COLORS( SGNODE* aParent )
{
m_node = new SGCOLORS( nullptr );
m_node = new SGCOLORS( NULL );
if( !m_node->SetParent( aParent ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( aParent ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d" ), __FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -69,29 +82,39 @@ IFSG_COLORS::IFSG_COLORS( IFSG_NODE& aParent )
{
SGNODE* pp = aParent.GetRawPtr();
#ifdef DEBUG
// Braces needed due to dangling else warning from wxLogTrace macro
if( !pp )
#ifdef DEBUG
if( ! pp )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
BadParent );
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
}
#endif
#endif
m_node = new SGCOLORS( nullptr );
m_node = new SGCOLORS( NULL );
if( !m_node->SetParent( pp ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( pp ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -100,7 +123,7 @@ bool IFSG_COLORS::Attach( SGNODE* aNode )
if( m_node )
m_node->DisassociateWrapper( &m_node );
m_node = nullptr;
m_node = NULL;
if( !aNode )
return false;
@@ -126,12 +149,17 @@ bool IFSG_COLORS::NewNode( SGNODE* aParent )
if( aParent != m_node->GetParent() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGCOLORS" ),
__FILE__, __FUNCTION__, __LINE__,
aParent->GetNodeTypeName( aParent->GetNodeType() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid SGNODE parent (";
ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
ostr << ") to SGCOLORS";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
delete m_node;
m_node = nullptr;
m_node = NULL;
return false;
}
@@ -145,7 +173,17 @@ bool IFSG_COLORS::NewNode( IFSG_NODE& aParent )
{
SGNODE* np = aParent.GetRawPtr();
wxCHECK( np, false );
if( NULL == np )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return NewNode( np );
}
@@ -153,17 +191,37 @@ bool IFSG_COLORS::NewNode( IFSG_NODE& aParent )
bool IFSG_COLORS::GetColorList( size_t& aListSize, SGCOLOR*& aColorList )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGCOLORS*) m_node )->GetColorList( aListSize, aColorList );
return false;
}
return ((SGCOLORS*)m_node)->GetColorList( aListSize, aColorList );
}
bool IFSG_COLORS::SetColorList( size_t aListSize, const SGCOLOR* aColorList )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SGCOLORS*) m_node )->SetColorList( aListSize, aColorList );
return false;
}
((SGCOLORS*)m_node)->SetColorList( aListSize, aColorList );
return true;
}
@@ -171,9 +229,19 @@ bool IFSG_COLORS::SetColorList( size_t aListSize, const SGCOLOR* aColorList )
bool IFSG_COLORS::AddColor( double aRedValue, double aGreenValue, double aBlueValue )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SGCOLORS*) m_node )->AddColor( aRedValue, aGreenValue, aBlueValue );
return false;
}
((SGCOLORS*)m_node)->AddColor( aRedValue, aGreenValue, aBlueValue );
return true;
}
@@ -181,9 +249,19 @@ bool IFSG_COLORS::AddColor( double aRedValue, double aGreenValue, double aBlueVa
bool IFSG_COLORS::AddColor( const SGCOLOR& aColor )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SGCOLORS*) m_node )->AddColor( aColor );
return false;
}
((SGCOLORS*)m_node)->AddColor( aColor );
return true;
}
+55 -21
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -31,39 +30,50 @@
#include "3d_cache/sg/sg_coordindex.h"
extern char BadObject[];
extern char BadOperand[];
extern char BadParent[];
extern char WrongParent[];
IFSG_COORDINDEX::IFSG_COORDINDEX( bool create )
{
m_node = nullptr;
m_node = NULL;
if( !create )
return;
m_node = new SGCOORDINDEX( nullptr );
m_node = new SGCOORDINDEX( NULL );
m_node->AssociateWrapper( &m_node );
if( m_node )
m_node->AssociateWrapper( &m_node );
return;
}
IFSG_COORDINDEX::IFSG_COORDINDEX( SGNODE* aParent )
{
m_node = new SGCOORDINDEX( nullptr );
m_node = new SGCOORDINDEX( NULL );
if( !m_node->SetParent( aParent ) )
{
delete m_node;
m_node = nullptr;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -73,25 +83,35 @@ IFSG_COORDINDEX::IFSG_COORDINDEX( IFSG_NODE& aParent )
if( !pp )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
BadParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
m_node = new SGCOORDINDEX( nullptr );
m_node = new SGCOORDINDEX( NULL );
if( !m_node->SetParent( pp ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
delete m_node;
m_node = nullptr;
m_node = NULL;
return;
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -100,7 +120,7 @@ bool IFSG_COORDINDEX::Attach( SGNODE* aNode )
if( m_node )
m_node->DisassociateWrapper( &m_node );
m_node = nullptr;
m_node = NULL;
if( !aNode )
return false;
@@ -126,13 +146,17 @@ bool IFSG_COORDINDEX::NewNode( SGNODE* aParent )
if( aParent != m_node->GetParent() )
{
wxLogTrace( MASK_3D_SG,
wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGCOORDINDEX" ),
__FILE__, __FUNCTION__, __LINE__,
aParent->GetNodeTypeName( aParent->GetNodeType() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid SGNODE parent (";
ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
ostr << ") to SGCOORDINDEX";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
delete m_node;
m_node = nullptr;
m_node = NULL;
return false;
}
@@ -146,7 +170,17 @@ bool IFSG_COORDINDEX::NewNode( IFSG_NODE& aParent )
{
SGNODE* np = aParent.GetRawPtr();
wxCHECK( np, false );
if( NULL == np )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return NewNode( np );
}
+117 -39
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -30,39 +29,52 @@
#include "3d_cache/sg/sg_coords.h"
extern char BadObject[];
extern char BadParent[];
extern char WrongParent[];
IFSG_COORDS::IFSG_COORDS( bool create )
{
m_node = nullptr;
m_node = NULL;
if( !create )
return ;
m_node = new SGCOORDS( nullptr );
m_node = new SGCOORDS( NULL );
m_node->AssociateWrapper( &m_node );
if( m_node )
m_node->AssociateWrapper( &m_node );
return;
}
IFSG_COORDS::IFSG_COORDS( SGNODE* aParent )
{
m_node = new SGCOORDS( nullptr );
m_node = new SGCOORDS( NULL );
if( !m_node->SetParent( aParent ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( aParent ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -70,28 +82,39 @@ IFSG_COORDS::IFSG_COORDS( IFSG_NODE& aParent )
{
SGNODE* pp = aParent.GetRawPtr();
#ifdef DEBUG
if( !pp )
#ifdef DEBUG
if( ! pp )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
BadParent );
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
}
#endif
#endif
m_node = new SGCOORDS( nullptr );
m_node = new SGCOORDS( NULL );
if( !m_node->SetParent( pp ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( pp ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -100,7 +123,7 @@ bool IFSG_COORDS::Attach( SGNODE* aNode )
if( m_node )
m_node->DisassociateWrapper( &m_node );
m_node = nullptr;
m_node = NULL;
if( !aNode )
return false;
@@ -126,12 +149,17 @@ bool IFSG_COORDS::NewNode( SGNODE* aParent )
if( aParent != m_node->GetParent() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGCOORDS" ),
__FILE__, __FUNCTION__, __LINE__,
aParent->GetNodeTypeName( aParent->GetNodeType() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid SGNODE parent (";
ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
ostr << ") to SGCOORDS";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
delete m_node;
m_node = nullptr;
m_node = NULL;
return false;
}
@@ -145,7 +173,17 @@ bool IFSG_COORDS::NewNode( IFSG_NODE& aParent )
{
SGNODE* np = aParent.GetRawPtr();
wxCHECK( np, false );
if( NULL == np )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return NewNode( np );
}
@@ -153,17 +191,37 @@ bool IFSG_COORDS::NewNode( IFSG_NODE& aParent )
bool IFSG_COORDS::GetCoordsList( size_t& aListSize, SGPOINT*& aCoordsList )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGCOORDS*) m_node )->GetCoordsList( aListSize, aCoordsList );
return false;
}
return ((SGCOORDS*)m_node)->GetCoordsList( aListSize, aCoordsList );
}
bool IFSG_COORDS::SetCoordsList( size_t aListSize, const SGPOINT* aCoordsList )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SGCOORDS*) m_node )->SetCoordsList( aListSize, aCoordsList );
return false;
}
((SGCOORDS*)m_node)->SetCoordsList( aListSize, aCoordsList );
return true;
}
@@ -171,9 +229,19 @@ bool IFSG_COORDS::SetCoordsList( size_t aListSize, const SGPOINT* aCoordsList )
bool IFSG_COORDS::AddCoord( double aXValue, double aYValue, double aZValue )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SGCOORDS*) m_node )->AddCoord( aXValue, aYValue, aZValue );
return false;
}
((SGCOORDS*)m_node)->AddCoord( aXValue, aYValue, aZValue );
return true;
}
@@ -181,9 +249,19 @@ bool IFSG_COORDS::AddCoord( double aXValue, double aYValue, double aZValue )
bool IFSG_COORDS::AddCoord( const SGPOINT& aPoint )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SGCOORDS*) m_node )->AddCoord( aPoint );
return false;
}
((SGCOORDS*)m_node)->AddCoord( aPoint );
return true;
}
+69 -31
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -31,39 +30,52 @@
#include "3d_cache/sg/sg_faceset.h"
extern char BadObject[];
extern char BadParent[];
extern char WrongParent[];
IFSG_FACESET::IFSG_FACESET( bool create )
{
m_node = nullptr;
m_node = NULL;
if( !create )
return ;
m_node = new SGFACESET( nullptr );
m_node = new SGFACESET( NULL );
m_node->AssociateWrapper( &m_node );
if( m_node )
m_node->AssociateWrapper( &m_node );
return;
}
IFSG_FACESET::IFSG_FACESET( SGNODE* aParent )
{
m_node = new SGFACESET( nullptr );
m_node = new SGFACESET( NULL );
if( !m_node->SetParent( aParent ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( aParent ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -71,28 +83,39 @@ IFSG_FACESET::IFSG_FACESET( IFSG_NODE& aParent )
{
SGNODE* pp = aParent.GetRawPtr();
#ifdef DEBUG
#ifdef DEBUG
if( ! pp )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
BadParent );
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
}
#endif
#endif
m_node = new SGFACESET( nullptr );
m_node = new SGFACESET( NULL );
if( !m_node->SetParent( pp ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( pp ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -101,7 +124,7 @@ bool IFSG_FACESET::Attach( SGNODE* aNode )
if( m_node )
m_node->DisassociateWrapper( &m_node );
m_node = nullptr;
m_node = NULL;
if( !aNode )
return false;
@@ -127,12 +150,17 @@ bool IFSG_FACESET::NewNode( SGNODE* aParent )
if( aParent != m_node->GetParent() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGFACESET" ),
__FILE__, __FUNCTION__, __LINE__,
aParent->GetNodeTypeName( aParent->GetNodeType() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid SGNODE parent (";
ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
ostr << ") to SGFACESET";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
delete m_node;
m_node = nullptr;
m_node = NULL;
return false;
}
@@ -146,7 +174,17 @@ bool IFSG_FACESET::NewNode( IFSG_NODE& aParent )
{
SGNODE* np = aParent.GetRawPtr();
wxCHECK( np, false );
if( NULL == np )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return NewNode( np );
}
@@ -155,7 +193,7 @@ bool IFSG_FACESET::NewNode( IFSG_NODE& aParent )
bool IFSG_FACESET::CalcNormals( SGNODE** aPtr )
{
if( m_node )
return ( (SGFACESET*) m_node )->CalcNormals( aPtr );
return ((SGFACESET*)m_node)->CalcNormals( aPtr );
return false;
}
+43 -7
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -31,24 +30,51 @@
#include "3d_cache/sg/sg_coordindex.h"
extern char BadObject[];
extern char BadOperand[];
extern char BadParent[];
extern char WrongParent[];
IFSG_INDEX::IFSG_INDEX() : IFSG_NODE()
{
return;
}
bool IFSG_INDEX::GetIndices( size_t& nIndices, int*& aIndexList )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGINDEX*) m_node )->GetIndices( nIndices, aIndexList );
return false;
}
return ((SGINDEX*)m_node)->GetIndices( nIndices, aIndexList );
}
bool IFSG_INDEX::SetIndices( size_t nIndices, int* aIndexList )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SGINDEX*) m_node )->SetIndices( nIndices, aIndexList );
return false;
}
((SGINDEX*)m_node)->SetIndices( nIndices, aIndexList );
return true;
}
@@ -56,9 +82,19 @@ bool IFSG_INDEX::SetIndices( size_t nIndices, int* aIndexList )
bool IFSG_INDEX::AddIndex( int aIndex )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SGINDEX*) m_node )->AddIndex( aIndex );
return false;
}
((SGINDEX*)m_node)->AddIndex( aIndex );
return true;
}
+154 -23
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -31,17 +30,15 @@
#include "3d_cache/sg/sg_node.h"
#include "plugins/3dapi/ifsg_api.h"
// collection of common error strings used by the wrappers
char BadObject[] = " * [BUG] operating on an invalid wrapper (object may have been deleted)";
char BadOperand[] = " * [BUG] parameter aNode is an invalid wrapper; its data may have been deleted";
char BadParent[] = " * [BUG] invalid parent node (data may have been deleted)";
char WrongParent[] = " * [BUG] parent node type is incompatible";
IFSG_NODE::IFSG_NODE()
{
m_node = nullptr;
m_node = NULL;
}
@@ -49,6 +46,8 @@ IFSG_NODE::~IFSG_NODE()
{
if( m_node )
m_node->DisassociateWrapper( &m_node );
return;
}
@@ -58,11 +57,13 @@ void IFSG_NODE::Destroy( void )
m_node->DisassociateWrapper( &m_node );
delete m_node;
m_node = nullptr;
m_node = NULL;
return;
}
SGNODE* IFSG_NODE::GetRawPtr( void ) noexcept
SGNODE* IFSG_NODE::GetRawPtr( void )
{
return m_node;
}
@@ -70,7 +71,17 @@ SGNODE* IFSG_NODE::GetRawPtr( void ) noexcept
S3D::SGTYPES IFSG_NODE::GetNodeType( void ) const
{
wxCHECK( m_node, S3D::SGTYPE_END );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return S3D::SGTYPE_END;
}
return m_node->GetNodeType();
}
@@ -78,7 +89,17 @@ S3D::SGTYPES IFSG_NODE::GetNodeType( void ) const
SGNODE* IFSG_NODE::GetParent( void ) const
{
wxCHECK( m_node, nullptr );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return NULL;
}
return m_node->GetParent();
}
@@ -86,7 +107,17 @@ SGNODE* IFSG_NODE::GetParent( void ) const
bool IFSG_NODE::SetParent( SGNODE* aParent )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return m_node->SetParent( aParent );
}
@@ -94,40 +125,90 @@ bool IFSG_NODE::SetParent( SGNODE* aParent )
const char* IFSG_NODE::GetName( void )
{
wxCHECK( m_node, nullptr );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return NULL;
}
return m_node->GetName();
}
bool IFSG_NODE::SetName( const char* aName )
bool IFSG_NODE::SetName( const char *aName )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
m_node->SetName( aName );
return true;
}
const char* IFSG_NODE::GetNodeTypeName( S3D::SGTYPES aNodeType ) const
const char * IFSG_NODE::GetNodeTypeName( S3D::SGTYPES aNodeType ) const
{
wxCHECK( m_node, nullptr );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return NULL;
}
return m_node->GetNodeTypeName( aNodeType );
}
SGNODE* IFSG_NODE::FindNode( const char* aNodeName )
SGNODE* IFSG_NODE::FindNode( const char *aNodeName )
{
wxCHECK( m_node, nullptr );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return m_node->FindNode( aNodeName, nullptr );
return NULL;
}
return m_node->FindNode( aNodeName, NULL );
}
bool IFSG_NODE::AddRefNode( SGNODE* aNode )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return m_node->AddRefNode( aNode );
}
@@ -135,11 +216,31 @@ bool IFSG_NODE::AddRefNode( SGNODE* aNode )
bool IFSG_NODE::AddRefNode( IFSG_NODE& aNode )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
SGNODE* np = aNode.GetRawPtr();
wxCHECK( np, false );
if( NULL == np )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadOperand;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return m_node->AddRefNode( np );
}
@@ -147,7 +248,17 @@ bool IFSG_NODE::AddRefNode( IFSG_NODE& aNode )
bool IFSG_NODE::AddChildNode( SGNODE* aNode )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return m_node->AddChildNode( aNode );
}
@@ -155,11 +266,31 @@ bool IFSG_NODE::AddChildNode( SGNODE* aNode )
bool IFSG_NODE::AddChildNode( IFSG_NODE& aNode )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
SGNODE* np = aNode.GetRawPtr();
wxCHECK( np, false );
if( NULL == np )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadOperand;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return m_node->AddChildNode( np );
}
+117 -38
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -31,39 +30,53 @@
#include "3d_cache/sg/sg_normals.h"
extern char BadObject[];
extern char BadOperand[];
extern char BadParent[];
extern char WrongParent[];
IFSG_NORMALS::IFSG_NORMALS( bool create )
{
m_node = nullptr;
m_node = NULL;
if( !create )
return;
m_node = new SGNORMALS( nullptr );
m_node = new SGNORMALS( NULL );
m_node->AssociateWrapper( &m_node );
if( m_node )
m_node->AssociateWrapper( &m_node );
return;
}
IFSG_NORMALS::IFSG_NORMALS( SGNODE* aParent )
{
m_node = new SGNORMALS( nullptr );
m_node = new SGNORMALS( NULL );
if( !m_node->SetParent( aParent ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( aParent ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -71,28 +84,39 @@ IFSG_NORMALS::IFSG_NORMALS( IFSG_NODE& aParent )
{
SGNODE* pp = aParent.GetRawPtr();
#ifdef DEBUG
#ifdef DEBUG
if( ! pp )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
BadParent );
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
}
#endif
#endif
m_node = new SGNORMALS( nullptr );
m_node = new SGNORMALS( NULL );
if( !m_node->SetParent( pp ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( pp ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -101,7 +125,7 @@ bool IFSG_NORMALS::Attach( SGNODE* aNode )
if( m_node )
m_node->DisassociateWrapper( &m_node );
m_node = nullptr;
m_node = NULL;
if( !aNode )
return false;
@@ -127,12 +151,17 @@ bool IFSG_NORMALS::NewNode( SGNODE* aParent )
if( aParent != m_node->GetParent() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGNORMALS" ),
__FILE__, __FUNCTION__, __LINE__,
aParent->GetNodeTypeName( aParent->GetNodeType() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid SGNODE parent (";
ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
ostr << ") to SGNORMALS";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
delete m_node;
m_node = nullptr;
m_node = NULL;
return false;
}
@@ -146,7 +175,17 @@ bool IFSG_NORMALS::NewNode( IFSG_NODE& aParent )
{
SGNODE* np = aParent.GetRawPtr();
wxCHECK( np, false );
if( NULL == np )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return NewNode( np );
}
@@ -154,34 +193,74 @@ bool IFSG_NORMALS::NewNode( IFSG_NODE& aParent )
bool IFSG_NORMALS::GetNormalList( size_t& aListSize, SGVECTOR*& aNormalList )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return ( (SGNORMALS*) m_node )->GetNormalList( aListSize, aNormalList );
return false;
}
return ((SGNORMALS*)m_node)->GetNormalList( aListSize, aNormalList );
}
bool IFSG_NORMALS::SetNormalList( size_t aListSize, const SGVECTOR* aNormalList )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SGNORMALS*) m_node )->SetNormalList( aListSize, aNormalList );
return false;
}
((SGNORMALS*)m_node)->SetNormalList( aListSize, aNormalList );
return true;
}
bool IFSG_NORMALS::AddNormal( double aXValue, double aYValue, double aZValue )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SGNORMALS*) m_node )->AddNormal( aXValue, aYValue, aZValue );
return false;
}
((SGNORMALS*)m_node)->AddNormal( aXValue, aYValue, aZValue );
return true;
}
bool IFSG_NORMALS::AddNormal( const SGVECTOR& aNormal )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SGNORMALS*) m_node )->AddNormal( aNormal );
return false;
}
((SGNORMALS*)m_node)->AddNormal( aNormal );
return true;
}
+70 -31
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -31,39 +30,53 @@
#include "3d_cache/sg/sg_shape.h"
extern char BadObject[];
extern char BadOperand[];
extern char BadParent[];
extern char WrongParent[];
IFSG_SHAPE::IFSG_SHAPE( bool create )
{
m_node = nullptr;
m_node = NULL;
if( !create )
return ;
m_node = new SGSHAPE( nullptr );
m_node = new SGSHAPE( NULL );
m_node->AssociateWrapper( &m_node );
if( m_node )
m_node->AssociateWrapper( &m_node );
return;
}
IFSG_SHAPE::IFSG_SHAPE( SGNODE* aParent )
{
m_node = new SGSHAPE( nullptr );
m_node = new SGSHAPE( NULL );
if( !m_node->SetParent( aParent ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( aParent ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -71,28 +84,39 @@ IFSG_SHAPE::IFSG_SHAPE( IFSG_NODE& aParent )
{
SGNODE* pp = aParent.GetRawPtr();
#ifdef DEBUG
if( !pp )
#ifdef DEBUG
if( ! pp )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
BadParent );
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
}
#endif
#endif
m_node = new SGSHAPE( nullptr );
m_node = new SGSHAPE( NULL );
if( !m_node->SetParent( pp ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( pp ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -101,7 +125,7 @@ bool IFSG_SHAPE::Attach( SGNODE* aNode )
if( m_node )
m_node->DisassociateWrapper( &m_node );
m_node = nullptr;
m_node = NULL;
if( !aNode )
return false;
@@ -127,12 +151,17 @@ bool IFSG_SHAPE::NewNode( SGNODE* aParent )
if( aParent != m_node->GetParent() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGSHAPE" ),
__FILE__, __FUNCTION__, __LINE__,
aParent->GetNodeTypeName( aParent->GetNodeType() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid SGNODE parent (";
ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
ostr << ") to SGSHAPE";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
delete m_node;
m_node = nullptr;
m_node = NULL;
return false;
}
@@ -146,7 +175,17 @@ bool IFSG_SHAPE::NewNode( IFSG_NODE& aParent )
{
SGNODE* np = aParent.GetRawPtr();
wxCHECK( np, false );
if( NULL == np )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return NewNode( np );
}
+132 -40
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -31,38 +30,52 @@
#include "3d_cache/sg/scenegraph.h"
extern char BadObject[];
extern char BadOperand[];
extern char BadParent[];
extern char WrongParent[];
IFSG_TRANSFORM::IFSG_TRANSFORM( bool create )
{
m_node = nullptr;
m_node = NULL;
if( !create )
return;
m_node = new SCENEGRAPH( nullptr );
m_node = new SCENEGRAPH( NULL );
m_node->AssociateWrapper( &m_node );
if( m_node )
m_node->AssociateWrapper( &m_node );
return;
}
IFSG_TRANSFORM::IFSG_TRANSFORM( SGNODE* aParent )
{
m_node = new SCENEGRAPH( nullptr );
m_node = new SCENEGRAPH( NULL );
if( !m_node->SetParent( aParent ) )
if( m_node )
{
delete m_node;
m_node = nullptr;
if( !m_node->SetParent( aParent ) )
{
delete m_node;
m_node = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
WrongParent );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << WrongParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
return;
}
m_node->AssociateWrapper( &m_node );
}
m_node->AssociateWrapper( &m_node );
return;
}
@@ -71,7 +84,7 @@ bool IFSG_TRANSFORM::Attach( SGNODE* aNode )
if( m_node )
m_node->DisassociateWrapper( &m_node );
m_node = nullptr;
m_node = NULL;
if( !aNode )
return false;
@@ -97,12 +110,17 @@ bool IFSG_TRANSFORM::NewNode( SGNODE* aParent )
if( aParent != m_node->GetParent() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SCENEGRAPH" ),
__FILE__, __FUNCTION__, __LINE__,
aParent->GetNodeTypeName( aParent->GetNodeType() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid SGNODE parent (";
ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
ostr << ") to SCENEGRAPH";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
delete m_node;
m_node = nullptr;
m_node = NULL;
return false;
}
@@ -116,7 +134,17 @@ bool IFSG_TRANSFORM::NewNode( IFSG_NODE& aParent )
{
SGNODE* np = aParent.GetRawPtr();
wxCHECK( np, false );
if( NULL == np )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadParent;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return NewNode( np );
}
@@ -124,20 +152,40 @@ bool IFSG_TRANSFORM::NewNode( IFSG_NODE& aParent )
bool IFSG_TRANSFORM::SetRotation( const SGVECTOR& aRotationAxis, double aAngle )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SCENEGRAPH*) m_node )->rotation_axis = aRotationAxis;
( (SCENEGRAPH*) m_node )->rotation_angle = aAngle;
return false;
}
((SCENEGRAPH*)m_node)->rotation_axis = aRotationAxis;
((SCENEGRAPH*)m_node)->rotation_angle = aAngle;
return true;
}
bool IFSG_TRANSFORM::SetScale( const SGPOINT& aScale ) noexcept
bool IFSG_TRANSFORM::SetScale( const SGPOINT& aScale )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SCENEGRAPH*) m_node )->scale = aScale;
return false;
}
((SCENEGRAPH*)m_node)->scale = aScale;
return true;
}
@@ -145,27 +193,51 @@ bool IFSG_TRANSFORM::SetScale( const SGPOINT& aScale ) noexcept
bool IFSG_TRANSFORM::SetScale( double aScale )
{
wxCHECK( m_node, false );
if( aScale < 1e-8 && aScale > -1e-8 )
if( NULL == m_node )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] |scale| is < 1e-8 - this seems strange" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
( (SCENEGRAPH*) m_node )->scale = SGPOINT( aScale, aScale, aScale );
if( aScale < 1e-8 && aScale > -1e-8 )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] |scale| is < 1e-8 - this seems strange";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
((SCENEGRAPH*)m_node)->scale = SGPOINT( aScale, aScale, aScale );
return true;
}
bool IFSG_TRANSFORM::SetTranslation( const SGPOINT& aTranslation ) noexcept
bool IFSG_TRANSFORM::SetTranslation( const SGPOINT& aTranslation )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SCENEGRAPH*) m_node )->translation = aTranslation;
return false;
}
((SCENEGRAPH*)m_node)->translation = aTranslation;
return true;
}
@@ -173,20 +245,40 @@ bool IFSG_TRANSFORM::SetTranslation( const SGPOINT& aTranslation ) noexcept
bool IFSG_TRANSFORM::SetScaleOrientation( const SGVECTOR& aScaleAxis, double aAngle )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SCENEGRAPH*) m_node )->scale_axis = aScaleAxis;
( (SCENEGRAPH*) m_node )->scale_angle = aAngle;
return false;
}
((SCENEGRAPH*)m_node)->scale_axis = aScaleAxis;
((SCENEGRAPH*)m_node)->scale_angle = aAngle;
return true;
}
bool IFSG_TRANSFORM::SetCenter( const SGPOINT& aCenter ) noexcept
bool IFSG_TRANSFORM::SetCenter( const SGPOINT& aCenter )
{
wxCHECK( m_node, false );
if( NULL == m_node )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << BadObject;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
( (SCENEGRAPH*) m_node )->center = aCenter;
return false;
}
((SCENEGRAPH*)m_node)->center = aCenter;
return true;
}
+197 -113
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -45,19 +44,24 @@ SCENEGRAPH::SCENEGRAPH( SGNODE* aParent ) : SGNODE( aParent )
scale.y = 1.0;
scale.z = 1.0;
if( nullptr != aParent && S3D::SGTYPE_TRANSFORM != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_TRANSFORM != aParent->GetNodeType() )
{
m_Parent = nullptr;
m_Parent = NULL;
wxLogTrace( MASK_3D_SG,
wxT( "%s:%s:%d * [BUG] inappropriate parent to SCENEGRAPH (type %d)" ),
__FILE__, __FUNCTION__, __LINE__,
aParent->GetNodeType() );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] inappropriate parent to SCENEGRAPH (type ";
ostr << aParent->GetNodeType() << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
}
else if( nullptr != aParent && S3D::SGTYPE_TRANSFORM == aParent->GetNodeType() )
else if( NULL != aParent && S3D::SGTYPE_TRANSFORM == aParent->GetNodeType() )
{
m_Parent->AddChildNode( this );
}
return;
}
@@ -70,12 +74,14 @@ SCENEGRAPH::~SCENEGRAPH()
// delete owned objects
DEL_OBJS( SCENEGRAPH, m_Transforms );
DEL_OBJS( SGSHAPE, m_Shape );
return;
}
bool SCENEGRAPH::SetParent( SGNODE* aParent, bool notify )
{
if( nullptr != m_Parent )
if( NULL != m_Parent )
{
if( aParent == m_Parent )
return true;
@@ -84,14 +90,14 @@ bool SCENEGRAPH::SetParent( SGNODE* aParent, bool notify )
if( notify )
m_Parent->unlinkChildNode( this );
m_Parent = nullptr;
m_Parent = NULL;
if( nullptr == aParent )
if( NULL == aParent )
return true;
}
// only a transform may be parent to a transform
if( nullptr != aParent && S3D::SGTYPE_TRANSFORM != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_TRANSFORM != aParent->GetNodeType() )
return false;
m_Parent = aParent;
@@ -105,8 +111,8 @@ bool SCENEGRAPH::SetParent( SGNODE* aParent, bool notify )
SGNODE* SCENEGRAPH::FindNode(const char *aNodeName, const SGNODE *aCaller)
{
if( nullptr == aNodeName || 0 == aNodeName[0] )
return nullptr;
if( NULL == aNodeName || 0 == aNodeName[0] )
return NULL;
if( !m_Name.compare( aNodeName ) )
return this;
@@ -115,8 +121,8 @@ SGNODE* SCENEGRAPH::FindNode(const char *aNodeName, const SGNODE *aCaller)
FIND_NODE( SGSHAPE, aNodeName, m_Shape, aCaller );
// query the parent if appropriate
if( aCaller == m_Parent || nullptr == m_Parent )
return nullptr;
if( aCaller == m_Parent || NULL == m_Parent )
return NULL;
return m_Parent->FindNode( aNodeName, this );
}
@@ -124,26 +130,33 @@ SGNODE* SCENEGRAPH::FindNode(const char *aNodeName, const SGNODE *aCaller)
void SCENEGRAPH::unlinkNode( const SGNODE* aNode, bool isChild )
{
if( nullptr == aNode )
if( NULL == aNode )
return;
switch( aNode->GetNodeType() )
{
case S3D::SGTYPE_TRANSFORM:
UNLINK_NODE( S3D::SGTYPE_TRANSFORM, SCENEGRAPH, aNode, m_Transforms, m_RTransforms,
isChild );
break;
case S3D::SGTYPE_TRANSFORM:
UNLINK_NODE( S3D::SGTYPE_TRANSFORM, SCENEGRAPH, aNode, m_Transforms, m_RTransforms, isChild );
break;
case S3D::SGTYPE_SHAPE:
UNLINK_NODE( S3D::SGTYPE_SHAPE, SGSHAPE, aNode, m_Shape, m_RShape, isChild );
break;
case S3D::SGTYPE_SHAPE:
UNLINK_NODE( S3D::SGTYPE_SHAPE, SGSHAPE, aNode, m_Shape, m_RShape, isChild );
break;
default:
break;
default:
break;
}
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] unlinkNode() did not find its target" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unlinkNode() did not find its target";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return;
}
@@ -163,16 +176,30 @@ void SCENEGRAPH::unlinkRefNode( const SGNODE* aNode )
bool SCENEGRAPH::addNode( SGNODE* aNode, bool isChild )
{
wxCHECK( aNode, false );
if( NULL == aNode )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL pointer passed for aNode";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
ADD_NODE( S3D::SGTYPE_TRANSFORM, SCENEGRAPH, aNode, m_Transforms, m_RTransforms, isChild );
ADD_NODE( S3D::SGTYPE_SHAPE, SGSHAPE, aNode, m_Shape, m_RShape, isChild );
wxLogTrace( MASK_3D_SG,
wxT( "%s:%s:%d * [BUG] object '%s' is not a valid type for this object (%d)" ),
__FILE__, __FUNCTION__, __LINE__,
aNode->GetName(),
aNode->GetNodeType() );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] object '" << aNode->GetName();
ostr << "' is not a valid type for this object (" << aNode->GetNodeType() << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
@@ -210,7 +237,7 @@ void SCENEGRAPH::ReNameNodes( void )
++sL;
}
} while( 0 );
} while(0);
// rename all transforms
do
@@ -224,13 +251,16 @@ void SCENEGRAPH::ReNameNodes( void )
++sL;
}
} while( 0 );
} while(0);
return;
}
bool SCENEGRAPH::WriteVRML( std::ostream& aFile, bool aReuseFlag )
{
if( m_Transforms.empty() && m_RTransforms.empty() && m_Shape.empty() && m_RShape.empty() )
if( m_Transforms.empty() && m_RTransforms.empty()
&& m_Shape.empty() && m_RShape.empty() )
{
return false;
}
@@ -336,14 +366,14 @@ bool SCENEGRAPH::WriteVRML( std::ostream& aFile, bool aReuseFlag )
bool SCENEGRAPH::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( nullptr == parentNode && nullptr != m_Parent )
if( NULL == parentNode && NULL != m_Parent )
{
SGNODE* np = m_Parent;
while( nullptr != np->GetParent() )
while( NULL != np->GetParent() )
np = np->GetParent();
if( np->WriteCache( aFile, nullptr ) )
if( np->WriteCache( aFile, NULL ) )
{
m_written = true;
return true;
@@ -352,9 +382,19 @@ bool SCENEGRAPH::WriteCache( std::ostream& aFile, SGNODE* parentNode )
return false;
}
wxCHECK( parentNode == m_Parent, false );
if( parentNode != m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; parentNode != m_aParent";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
if( nullptr == m_Parent )
return false;
}
if( NULL == m_Parent )
{
// ensure unique node names
ResetNodeIndex();
@@ -363,8 +403,12 @@ bool SCENEGRAPH::WriteCache( std::ostream& aFile, SGNODE* parentNode )
if( aFile.fail() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad stream" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad stream";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -420,9 +464,12 @@ bool SCENEGRAPH::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( !m_Transforms[i]->WriteCache( aFile, this ) )
{
wxLogTrace( MASK_3D_SG,
wxT( "%s:%s:%d * [INFO] bad stream while writing child transforms" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad stream while writing child transforms";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -430,20 +477,21 @@ bool SCENEGRAPH::WriteCache( std::ostream& aFile, SGNODE* parentNode )
// write referenced transform names
asize = m_RTransforms.size();
for( i = 0; i < asize; ++i )
aFile << "[" << m_RTransforms[i]->GetName() << "]";
// write child shapes
asize = m_Shape.size();
for( i = 0; i < asize; ++i )
{
if( !m_Shape[i]->WriteCache( aFile, this ) )
{
wxLogTrace( MASK_3D_SG,
wxT( "%s:%s:%d * [INFO] bad stream while writing child shapes" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad stream while writing child shapes";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -451,7 +499,6 @@ bool SCENEGRAPH::WriteCache( std::ostream& aFile, SGNODE* parentNode )
// write referenced transform names
asize = m_RShape.size();
for( i = 0; i < asize; ++i )
aFile << "[" << m_RShape[i]->GetName() << "]";
@@ -465,20 +512,33 @@ bool SCENEGRAPH::WriteCache( std::ostream& aFile, SGNODE* parentNode )
bool SCENEGRAPH::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
wxCHECK( m_Transforms.empty() && m_RTransforms.empty() && m_Shape.empty() && m_RShape.empty(),
false );
if( !m_Transforms.empty() || !m_RTransforms.empty()
|| !m_Shape.empty() || !m_RShape.empty() )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] non-empty node";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
std::string name; // name of the node
if( nullptr == parentNode )
if( NULL == parentNode )
{
// we need to read the tag and verify its type
if( S3D::SGTYPE_TRANSFORM != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; tag mismatch at position "
"%ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; tag mismatch at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -512,10 +572,13 @@ bool SCENEGRAPH::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_TRANSFORM != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child transform tag "
"at position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad child transform tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -525,10 +588,13 @@ bool SCENEGRAPH::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !sp->ReadCache( aFile, this ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data while reading transform "
"%ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data while reading transform '";
ostr << name << "' pos " << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -539,10 +605,13 @@ bool SCENEGRAPH::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_TRANSFORM != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref transform tag at "
"position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad ref transform tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -551,20 +620,26 @@ bool SCENEGRAPH::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !sp )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: cannot find ref "
"transform at position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: cannot find ref transform '";
ostr << name << "' pos " << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( S3D::SGTYPE_TRANSFORM != sp->GetNodeType() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: type is not TRANSFORM "
"at position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: type is not TRANSFORM '";
ostr << name << "' pos " << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -577,10 +652,13 @@ bool SCENEGRAPH::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_SHAPE != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child shape tag at "
"position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad child shape tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -590,10 +668,13 @@ bool SCENEGRAPH::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !sp->ReadCache( aFile, this ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; corrupt data while "
"reading shape at position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data while reading shape '";
ostr << name << "' pos " << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -604,10 +685,13 @@ bool SCENEGRAPH::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_SHAPE != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref shape tag at "
"position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad ref shape tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -616,20 +700,26 @@ bool SCENEGRAPH::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !sp )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: cannot find ref shape "
"at position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: cannot find ref shape '";
ostr << name << "' pos " << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( S3D::SGTYPE_SHAPE != sp->GetNodeType() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: type is not SGSHAPE at "
"position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: type is not SGSHAPE '";
ostr << name << "' pos " << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -644,27 +734,21 @@ bool SCENEGRAPH::ReadCache( std::istream& aFile, SGNODE* parentNode )
}
bool SCENEGRAPH::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
std::vector< SMESH >& meshes )
bool SCENEGRAPH::Prepare( const glm::dmat4* aTransform,
S3D::MATLIST& materials, std::vector< SMESH >& meshes )
{
// calculate the accumulated transform
double rX, rY, rZ;
// rotation
rotation_axis.GetVector( rX, rY, rZ );
glm::dmat4 rM = glm::rotate( glm::dmat4( 1.0 ), rotation_angle, glm::dvec3( rX, rY, rZ ) );
// translation
glm::dmat4 tM = glm::translate( glm::dmat4( 1.0 ), glm::dvec3( translation.x, translation.y,
translation.z ) );
glm::dmat4 tM = glm::translate( glm::dmat4( 1.0 ), glm::dvec3( translation.x, translation.y, translation.z ) );
// center
glm::dmat4 cM = glm::translate( glm::dmat4( 1.0 ), glm::dvec3( center.x, center.y, center.z ) );
glm::dmat4 ncM = glm::translate( glm::dmat4( 1.0 ), glm::dvec3( -center.x, -center.y,
-center.z ) );
glm::dmat4 ncM = glm::translate( glm::dmat4( 1.0 ), glm::dvec3( -center.x, -center.y, -center.z ) );
// scale
glm::dmat4 sM = glm::scale( glm::dmat4( 1.0 ), glm::dvec3( scale.x, scale.y, scale.z ) );
// scaleOrientation
scale_axis.GetVector( rX, rY, rZ );
glm::dmat4 srM = glm::rotate( glm::dmat4( 1.0 ), scale_angle, glm::dvec3( rX, rY, rZ ) );
@@ -676,7 +760,7 @@ bool SCENEGRAPH::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
// tx0 = tM * cM * rM * srM * sM * nsrM * ncM
glm::dmat4 tx0;
if( nullptr != aTransform )
if( NULL != aTransform )
tx0 = (*aTransform) * tM * cM * rM * srM * sM * nsrM * ncM;
else
tx0 = tM * cM * rM * srM * sM * nsrM * ncM;
@@ -704,7 +788,7 @@ bool SCENEGRAPH::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
++sL;
}
} while( 0 );
} while(0);
// prepare all transforms
do
@@ -727,7 +811,7 @@ bool SCENEGRAPH::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
++sL;
}
} while( 0 );
} while(0);
return ok;
}
+32 -36
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,6 +23,10 @@
/**
* @file scenegraph.h
* defines the basic data set required to represent a 3D model;
* this model must remain compatible with VRML2.0 in order to
* facilitate VRML export of scene graph data created by available
* 3D plugins.
*/
@@ -35,18 +38,38 @@
class SGSHAPE;
/**
* Define the basic data set required to represent a 3D model.
*
* This model must remain compatible with VRML2.0 in order to facilitate VRML export of
* scene graph data created by available 3D plugins.
*/
class SCENEGRAPH : public SGNODE
{
private:
// The following are items which may be defined for reuse
// in a VRML output file. They do not necessarily correspond
// to the use of DEF within a VRML input file; it is the
// responsibility of the plugin to perform any necessary
// conversions to comply with the restrictions imposed by
// this scene graph structure
std::vector< SCENEGRAPH* > m_Transforms; // local Transform nodes
std::vector< SGSHAPE* > m_Shape; // local Shape nodes
std::vector< SCENEGRAPH* > m_RTransforms; // referenced Transform nodes
std::vector< SGSHAPE* > m_RShape; // referenced Shape nodes
void unlinkNode( const SGNODE* aNode, bool isChild );
bool addNode( SGNODE* aNode, bool isChild );
public:
void unlinkChildNode( const SGNODE* aNode ) override;
void unlinkRefNode( const SGNODE* aNode ) override;
public:
// note: order of transformation is Translate, Rotate, Offset
SGPOINT center;
SGPOINT translation;
SGVECTOR rotation_axis;
double rotation_angle; // radians
SGPOINT scale;
SGVECTOR scale_axis;
double scale_angle; // radians
SCENEGRAPH( SGNODE* aParent );
virtual ~SCENEGRAPH();
@@ -61,35 +84,8 @@ public:
bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
bool Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
std::vector< SMESH >& meshes );
private:
void unlinkNode( const SGNODE* aNode, bool isChild );
bool addNode( SGNODE* aNode, bool isChild );
public:
// note: order of transformation is Translate, Rotate, Offset
SGPOINT center;
SGPOINT translation;
SGVECTOR rotation_axis;
double rotation_angle; // radians
SGPOINT scale;
SGVECTOR scale_axis;
double scale_angle; // radians
private:
// The following are items which may be defined for reuse
// in a VRML output file. They do not necessarily correspond
// to the use of DEF within a VRML input file; it is the
// responsibility of the plugin to perform any necessary
// conversions to comply with the restrictions imposed by
// this scene graph structure
std::vector< SCENEGRAPH* > m_Transforms; // local Transform nodes
std::vector< SGSHAPE* > m_Shape; // local Shape nodes
std::vector< SCENEGRAPH* > m_RTransforms; // referenced Transform nodes
std::vector< SGSHAPE* > m_RShape; // referenced Shape nodes
bool Prepare( const glm::dmat4* aTransform,
S3D::MATLIST& materials, std::vector< SMESH >& meshes );
};
/*
+141 -52
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -30,40 +29,46 @@
#include "3d_cache/sg/sg_appearance.h"
#include "3d_cache/sg/sg_helpers.h"
SGAPPEARANCE::SGAPPEARANCE( SGNODE* aParent ) : SGNODE( aParent )
SGAPPEARANCE::SGAPPEARANCE( SGNODE* aParent ) : SGNODE( aParent)
{
m_SGtype = S3D::SGTYPE_APPEARANCE;
// defaults in accord with VRML2.0 spec
ambient.SetColor( 0.05317f, 0.17879f, 0.01804f );
shininess = 0.2f;
transparency = 0.0f;
diffuse.SetColor( 0.8f, 0.8f, 0.8f );
ambient.SetColor( 0.05317, 0.17879, 0.01804 );
shininess = 0.2;
transparency = 0.0;
diffuse.SetColor( 0.8, 0.8, 0.8 );
if( nullptr != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
{
m_Parent = nullptr;
m_Parent = NULL;
wxLogTrace( MASK_3D_SG,
wxT( "%s:%s:%d * [BUG] inappropriate parent to SGAPPEARANCE (type %s )" ),
__FILE__, __FUNCTION__, __LINE__, aParent->GetNodeType() );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] inappropriate parent to SGAPPEARANCE (type ";
ostr << aParent->GetNodeType() << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
}
else if( nullptr != aParent && S3D::SGTYPE_SHAPE == aParent->GetNodeType() )
else if( NULL != aParent && S3D::SGTYPE_SHAPE == aParent->GetNodeType() )
{
m_Parent->AddChildNode( this );
}
return;
}
SGAPPEARANCE::~SGAPPEARANCE()
{
return;
}
bool SGAPPEARANCE::SetParent( SGNODE* aParent, bool notify )
{
if( nullptr != m_Parent )
if( NULL != m_Parent )
{
if( aParent == m_Parent )
return true;
@@ -72,14 +77,14 @@ bool SGAPPEARANCE::SetParent( SGNODE* aParent, bool notify )
if( notify )
m_Parent->unlinkChildNode( this );
m_Parent = nullptr;
m_Parent = NULL;
if( nullptr == aParent )
if( NULL == aParent )
return true;
}
// only a SGSHAPE may be parent to a SGAPPEARANCE
if( nullptr != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
return false;
m_Parent = aParent;
@@ -99,7 +104,17 @@ bool SGAPPEARANCE::SetEmissive( float aRVal, float aGVal, float aBVal )
bool SGAPPEARANCE::SetEmissive( const SGCOLOR* aRGBColor )
{
wxCHECK_MSG( aRGBColor, false, wxT( "NULL pointer passed for aRGBColor" ) );
if( NULL == aRGBColor )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL pointer passed for aRGBColor";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return emissive.SetColor( aRGBColor );
}
@@ -119,7 +134,17 @@ bool SGAPPEARANCE::SetDiffuse( float aRVal, float aGVal, float aBVal )
bool SGAPPEARANCE::SetDiffuse( const SGCOLOR* aRGBColor )
{
wxCHECK_MSG( aRGBColor, false, wxT( "NULL pointer passed for aRGBColor" ) );
if( NULL == aRGBColor )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL pointer passed for aRGBColor";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return diffuse.SetColor( aRGBColor );
}
@@ -139,7 +164,17 @@ bool SGAPPEARANCE::SetSpecular( float aRVal, float aGVal, float aBVal )
bool SGAPPEARANCE::SetSpecular( const SGCOLOR* aRGBColor )
{
wxCHECK_MSG( aRGBColor, false, wxT( "NULL pointer passed for aRGBColor" ) );
if( NULL == aRGBColor )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL pointer passed for aRGBColor";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return specular.SetColor( aRGBColor );
}
@@ -158,7 +193,17 @@ bool SGAPPEARANCE::SetAmbient( float aRVal, float aGVal, float aBVal )
bool SGAPPEARANCE::SetAmbient( const SGCOLOR* aRGBColor )
{
wxCHECK_MSG( aRGBColor, false, wxT( "NULL pointer passed for aRGBColor" ) );
if( NULL == aRGBColor )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL pointer passed for aRGBColor";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
return ambient.SetColor( aRGBColor );
}
@@ -170,46 +215,66 @@ bool SGAPPEARANCE::SetAmbient( const SGCOLOR& aRGBColor )
}
SGNODE* SGAPPEARANCE::FindNode( const char* aNodeName, const SGNODE* aCaller) noexcept
SGNODE* SGAPPEARANCE::FindNode(const char *aNodeName, const SGNODE *aCaller)
{
if( nullptr == aNodeName || 0 == aNodeName[0] )
return nullptr;
if( NULL == aNodeName || 0 == aNodeName[0] )
return NULL;
if( !m_Name.compare( aNodeName ) )
return this;
return nullptr;
return NULL;
}
void SGAPPEARANCE::unlinkChildNode( const SGNODE* aCaller ) noexcept
void SGAPPEARANCE::unlinkChildNode( const SGNODE* aCaller )
{
wxCHECK_MSG( aCaller, /* void */,
wxT( "unexpected code branch; node should have no children or refs" ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unexpected code branch; node should have no children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
void SGAPPEARANCE::unlinkRefNode( const SGNODE* aCaller ) noexcept
void SGAPPEARANCE::unlinkRefNode( const SGNODE* aCaller )
{
wxCHECK_MSG( aCaller, /* void */,
wxT( "unexpected code branch; node should have no children or refs" ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unexpected code branch; node should have no children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
bool SGAPPEARANCE::AddRefNode( SGNODE* aNode ) noexcept
bool SGAPPEARANCE::AddRefNode( SGNODE* aNode )
{
wxCHECK_MSG( aNode, false, wxT( "this node does not accept children or refs" ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] this node does not accept children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
// This is redundant but it keeps gcc from generating a warning on debug builds.
return false;
}
bool SGAPPEARANCE::AddChildNode( SGNODE* aNode ) noexcept
bool SGAPPEARANCE::AddChildNode( SGNODE* aNode )
{
wxCHECK_MSG( aNode, false, wxT( "this node does not accept children or refs" ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] this node does not accept children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
// This is redundant but it keeps gcc from generating a warning on debug builds.
return false;
}
@@ -253,13 +318,13 @@ bool SGAPPEARANCE::WriteVRML( std::ostream& aFile, bool aReuseFlag )
diffuse.GetColor( ambr, ambg, ambb );
float den = ( 0.212671 * ambr + 0.71516 * ambg + 0.072169 * ambb );
if( den < 0.004f )
den = 0.004f;
if( den < 0.004 )
den = 0.004;
amb /= den;
if( amb > 1.0f )
amb = 1.0f;
if( amb > 1.0 )
amb = 1.0;
S3D::FormatFloat( tmp, amb );
aFile << " ambientIntensity " << tmp << "\n";
@@ -303,16 +368,26 @@ bool SGAPPEARANCE::WriteVRML( std::ostream& aFile, bool aReuseFlag )
bool SGAPPEARANCE::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( nullptr == parentNode )
if( NULL == parentNode )
{
wxCHECK_MSG( m_Parent, false, wxT( "corrupt data; m_aParent is NULL" ) );
if( NULL == m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; m_aParent is NULL";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
SGNODE* np = m_Parent;
while( nullptr != np->GetParent() )
while( NULL != np->GetParent() )
np = np->GetParent();
if( np->WriteCache( aFile, nullptr ) )
if( np->WriteCache( aFile, NULL ) )
{
m_written = true;
return true;
@@ -321,20 +396,34 @@ bool SGAPPEARANCE::WriteCache( std::ostream& aFile, SGNODE* parentNode )
return false;
}
wxCHECK_MSG( parentNode == m_Parent, false, wxT( "corrupt data; parentNode != m_aParent" ) );
if( parentNode != m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; parentNode != m_aParent";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( !aFile.good() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad stream" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad stream";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
aFile << "[" << GetName() << "]";
S3D::WriteColor( aFile, ambient );
aFile.write( (char*) &shininess, sizeof( shininess ) );
aFile.write( (char*) &transparency, sizeof( transparency ) );
aFile.write( (char*)&shininess, sizeof(shininess) );
aFile.write( (char*)&transparency, sizeof(transparency) );
S3D::WriteColor( aFile, diffuse );
S3D::WriteColor( aFile, emissive );
S3D::WriteColor( aFile, specular );
@@ -350,8 +439,8 @@ bool SGAPPEARANCE::WriteCache( std::ostream& aFile, SGNODE* parentNode )
bool SGAPPEARANCE::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
S3D::ReadColor( aFile, ambient );
aFile.read( (char*) &shininess, sizeof( shininess ) );
aFile.read( (char*) &transparency, sizeof( transparency ) );
aFile.read( (char*)&shininess, sizeof(shininess) );
aFile.read( (char*)&transparency, sizeof(transparency) );
S3D::ReadColor( aFile, diffuse );
S3D::ReadColor( aFile, emissive );
S3D::ReadColor( aFile, specular );
+14 -17
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,6 +23,7 @@
/**
* @file sg_appearance.h
* defines the generic material appearance of a scenegraph object
*/
#ifndef SG_APPEARANCE_H
@@ -31,15 +31,20 @@
#include "3d_cache/sg/sg_node.h"
/**
* Defines the generic material appearance of a scenegraph object.
*/
class SGAPPEARANCE : public SGNODE
{
public:
void unlinkChildNode( const SGNODE* aNode ) noexcept override;
void unlinkRefNode( const SGNODE* aNode ) noexcept override;
float shininess; // default 0.2
float transparency; // default 0.0
SGCOLOR ambient; // default 0.05317 0.17879 0.01804
SGCOLOR diffuse; // default 0.8 0.8 0.8
SGCOLOR emissive; // default 0.0 0.0 0.0
SGCOLOR specular; // default 0.0 0.0 0.0
void unlinkChildNode( const SGNODE* aNode ) override;
void unlinkRefNode( const SGNODE* aNode ) override;
public:
SGAPPEARANCE( SGNODE* aParent );
virtual ~SGAPPEARANCE();
@@ -61,23 +66,15 @@ public:
bool SetAmbient( const SGCOLOR* aRGBColor );
bool SetAmbient( const SGCOLOR& aRGBColor );
SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller) noexcept override;
bool AddRefNode( SGNODE* aNode ) noexcept override;
bool AddChildNode( SGNODE* aNode ) noexcept override;
SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller) override;
bool AddRefNode( SGNODE* aNode ) override;
bool AddChildNode( SGNODE* aNode ) override;
void ReNameNodes( void ) override;
bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) override;
bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
float shininess; // default 0.2
float transparency; // default 0.0
SGCOLOR ambient; // default 0.05317 0.17879 0.01804
SGCOLOR diffuse; // default 0.8 0.8 0.8
SGCOLOR emissive; // default 0.0 0.0 0.0
SGCOLOR specular; // default 0.0 0.0 0.0
};
#endif // SG_APPEARANCE_H
+96 -32
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -36,14 +35,20 @@ SGCOLOR::SGCOLOR()
red = 0.0;
green = 0.0;
blue = 0.0;
return;
}
SGCOLOR::SGCOLOR( float aRVal, float aGVal, float aBVal )
{
if( !checkRange( aRVal, aGVal, aBVal ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid value passed to constructor" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid value passed to constructor";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
red = 0.0;
green = 0.0;
blue = 0.0;
@@ -53,32 +58,46 @@ SGCOLOR::SGCOLOR( float aRVal, float aGVal, float aBVal )
red = aRVal;
green = aGVal;
blue = aBVal;
return;
}
void SGCOLOR::GetColor( float& aRedVal, float& aGreenVal, float& aBlueVal ) const noexcept
void SGCOLOR::GetColor( float& aRedVal, float& aGreenVal, float& aBlueVal ) const
{
aRedVal = red;
aGreenVal = green;
aBlueVal = blue;
return;
}
void SGCOLOR::GetColor( SGCOLOR& aColor ) const noexcept
void SGCOLOR::GetColor( SGCOLOR& aColor ) const
{
aColor.red = red;
aColor.green = green;
aColor.blue = blue;
return;
}
void SGCOLOR::GetColor( SGCOLOR* aColor ) const noexcept
void SGCOLOR::GetColor( SGCOLOR* aColor ) const
{
wxCHECK_MSG( aColor, /* void */, wxT( "NULL pointer passed for aRGBColor" ) );
if( NULL == aColor )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL pointer passed for aColor";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
aColor->red = red;
aColor->green = green;
aColor->blue = blue;
return;
}
@@ -95,7 +114,7 @@ bool SGCOLOR::SetColor( float aRedVal, float aGreenVal, float aBlueVal )
}
bool SGCOLOR::SetColor( const SGCOLOR& aColor ) noexcept
bool SGCOLOR::SetColor( const SGCOLOR& aColor )
{
red = aColor.red;
green = aColor.green;
@@ -104,9 +123,19 @@ bool SGCOLOR::SetColor( const SGCOLOR& aColor ) noexcept
}
bool SGCOLOR::SetColor( const SGCOLOR* aColor ) noexcept
bool SGCOLOR::SetColor( const SGCOLOR* aColor )
{
wxCHECK_MSG( aColor, false, wxT( "NULL pointer passed for aRGBColor" ) );
if( NULL == aColor )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL pointer passed for aColor";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
red = aColor->red;
green = aColor->green;
@@ -115,31 +144,42 @@ bool SGCOLOR::SetColor( const SGCOLOR* aColor ) noexcept
}
bool SGCOLOR::checkRange( float aRedVal, float aGreenVal, float aBlueVal ) const noexcept
bool SGCOLOR::checkRange( float aRedVal, float aGreenVal, float aBlueVal ) const
{
bool ok = true;
if( aRedVal < 0.0 || aRedVal > 1.0 )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid RED value: %g" ),
__FILE__, __FUNCTION__, __LINE__, aRedVal );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid RED value: " << aRedVal;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
ok = false;
}
if( aGreenVal < 0.0 || aGreenVal > 1.0 )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid GREEN value: %g" ),
__FILE__, __FUNCTION__, __LINE__, aGreenVal );
#ifdef DEBUG
if( ok )
{
wxLogTrace( MASK_3D_SG, "%s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__ );
}
wxLogTrace( MASK_3D_SG, " * [BUG] invalid GREEN value: %f\n", aGreenVal );
#endif
ok = false;
}
if( aBlueVal < 0.0 || aBlueVal > 1.0 )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid BLUE value: %g" ),
__FILE__, __FUNCTION__, __LINE__, aBlueVal );
#ifdef DEBUG
if( ok )
{
wxLogTrace( MASK_3D_SG, "%s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__ );
}
wxLogTrace( MASK_3D_SG, " * [BUG] invalid BLUE value: %f\n", aBlueVal );
#endif
ok = false;
}
@@ -152,10 +192,11 @@ SGPOINT::SGPOINT()
x = 0.0;
y = 0.0;
z = 0.0;
return;
}
SGPOINT::SGPOINT( double aXVal, double aYVal, double aZVal ) noexcept
SGPOINT::SGPOINT( double aXVal, double aYVal, double aZVal )
{
x = aXVal;
y = aYVal;
@@ -163,45 +204,60 @@ SGPOINT::SGPOINT( double aXVal, double aYVal, double aZVal ) noexcept
}
void SGPOINT::GetPoint( const double& aXVal, const double& aYVal, const double& aZVal ) noexcept
void SGPOINT::GetPoint( double& aXVal, double& aYVal, double& aZVal )
{
x = aXVal;
y = aYVal;
z = aZVal;
return;
}
void SGPOINT::GetPoint( const SGPOINT& aPoint ) noexcept
void SGPOINT::GetPoint( SGPOINT& aPoint )
{
x = aPoint.x;
y = aPoint.y;
z = aPoint.z;
return;
}
void SGPOINT::GetPoint( const SGPOINT* aPoint ) noexcept
void SGPOINT::GetPoint( SGPOINT* aPoint )
{
wxCHECK_MSG( aPoint, /* void */, wxT( "NULL pointer passed for aPoint" ) );
if( NULL == aPoint )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL pointer passed for aPoint";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
x = aPoint->x;
y = aPoint->y;
z = aPoint->z;
return;
}
void SGPOINT::SetPoint( double aXVal, double aYVal, double aZVal ) noexcept
void SGPOINT::SetPoint( double aXVal, double aYVal, double aZVal )
{
x = aXVal;
y = aYVal;
z = aZVal;
return;
}
void SGPOINT::SetPoint( const SGPOINT& aPoint ) noexcept
void SGPOINT::SetPoint( const SGPOINT& aPoint )
{
x = aPoint.x;
y = aPoint.y;
z = aPoint.z;
return;
}
@@ -210,6 +266,7 @@ SGVECTOR::SGVECTOR()
vx = 0.0;
vy = 0.0;
vz = 1.0;
return;
}
@@ -219,14 +276,16 @@ SGVECTOR::SGVECTOR( double aXVal, double aYVal, double aZVal )
vy = aYVal;
vz = aZVal;
normalize();
return;
}
void SGVECTOR::GetVector( double& aXVal, double& aYVal, double& aZVal ) const noexcept
void SGVECTOR::GetVector( double& aXVal, double& aYVal, double& aZVal ) const
{
aXVal = vx;
aYVal = vy;
aZVal = vz;
return;
}
@@ -236,25 +295,28 @@ void SGVECTOR::SetVector( double aXVal, double aYVal, double aZVal )
vy = aYVal;
vz = aZVal;
normalize();
return;
}
void SGVECTOR::SetVector( const SGVECTOR& aVector )
{
aVector.GetVector( vx, vy, vz );
return;
}
void SGVECTOR::normalize( void ) noexcept
void SGVECTOR::normalize( void )
{
double dx = vx * vx;
double dy = vy * vy;
double dz = vz * vz;
double dv2 = sqrt( dx + dy + dz );
if( ( dx + dy + dz ) < 1e-8 )
if( (dx + dy + dz) < 1e-8 )
{
// use the default; the numbers are too small to be believable
// use the default; the numbers are too small
// to be believable
vx = 0.0;
vy = 0.0;
vz = 1.0;
@@ -264,10 +326,12 @@ void SGVECTOR::normalize( void ) noexcept
vx /= dv2;
vy /= dv2;
vz /= dv2;
return;
}
SGVECTOR& SGVECTOR::operator=( const SGVECTOR& source ) noexcept
SGVECTOR& SGVECTOR::operator=( const SGVECTOR& source )
{
vx = source.vx;
vy = source.vy;
+99 -36
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -29,35 +28,41 @@
#include "3d_cache/sg/sg_colors.h"
#include "3d_cache/sg/sg_helpers.h"
SGCOLORS::SGCOLORS( SGNODE* aParent ) : SGNODE( aParent )
{
m_SGtype = S3D::SGTYPE_COLORS;
if( nullptr != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
{
m_Parent = nullptr;
m_Parent = NULL;
wxLogTrace( MASK_3D_SG,
wxT( "%s:%s:%d * [BUG] inappropriate parent to SGCOLORS (type %s)" ),
__FILE__, __FUNCTION__, __LINE__, aParent->GetNodeType() );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] inappropriate parent to SGCOLORS (type ";
ostr << aParent->GetNodeType() << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
}
else if( nullptr != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
else if( NULL != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
{
m_Parent->AddChildNode( this );
}
return;
}
SGCOLORS::~SGCOLORS()
{
colors.clear();
return;
}
bool SGCOLORS::SetParent( SGNODE* aParent, bool notify )
{
if( nullptr != m_Parent )
if( NULL != m_Parent )
{
if( aParent == m_Parent )
return true;
@@ -66,14 +71,14 @@ bool SGCOLORS::SetParent( SGNODE* aParent, bool notify )
if( notify )
m_Parent->unlinkChildNode( this );
m_Parent = nullptr;
m_Parent = NULL;
if( nullptr == aParent )
if( NULL == aParent )
return true;
}
// only a SGFACESET may be parent to a SGCOLORS
if( nullptr != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
return false;
m_Parent = aParent;
@@ -85,41 +90,65 @@ bool SGCOLORS::SetParent( SGNODE* aParent, bool notify )
}
SGNODE* SGCOLORS::FindNode(const char* aNodeName, const SGNODE *aCaller) noexcept
SGNODE* SGCOLORS::FindNode(const char *aNodeName, const SGNODE *aCaller)
{
if( nullptr == aNodeName || 0 == aNodeName[0] )
return nullptr;
if( NULL == aNodeName || 0 == aNodeName[0] )
return NULL;
if( !m_Name.compare( aNodeName ) )
return this;
return nullptr;
return NULL;
}
void SGCOLORS::unlinkChildNode( const SGNODE* aCaller ) noexcept
void SGCOLORS::unlinkChildNode( const SGNODE* aCaller )
{
wxCHECK( aCaller, /* void */ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unexpected code branch; node should have no children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
void SGCOLORS::unlinkRefNode( const SGNODE* aCaller ) noexcept
void SGCOLORS::unlinkRefNode( const SGNODE* aCaller )
{
wxCHECK( aCaller, /* void */ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unexpected code branch; node should have no children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
bool SGCOLORS::AddRefNode( SGNODE* aNode ) noexcept
bool SGCOLORS::AddRefNode( SGNODE* aNode )
{
wxCHECK( aNode, false );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] this node does not accept children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
bool SGCOLORS::AddChildNode( SGNODE* aNode ) noexcept
bool SGCOLORS::AddChildNode( SGNODE* aNode )
{
wxCHECK( aNode, false );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] this node does not accept children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -130,7 +159,7 @@ bool SGCOLORS::GetColorList( size_t& aListSize, SGCOLOR*& aColorList )
if( colors.empty() )
{
aListSize = 0;
aColorList = nullptr;
aColorList = NULL;
return false;
}
@@ -144,7 +173,7 @@ void SGCOLORS::SetColorList( size_t aListSize, const SGCOLOR* aColorList )
{
colors.clear();
if( 0 == aListSize || nullptr == aColorList )
if( 0 == aListSize || NULL == aColorList )
return;
for( size_t i = 0; i < aListSize; ++i )
@@ -156,7 +185,7 @@ void SGCOLORS::SetColorList( size_t aListSize, const SGCOLOR* aColorList )
void SGCOLORS::AddColor( double aRedValue, double aGreenValue, double aBlueValue )
{
colors.emplace_back( aRedValue, aGreenValue, aBlueValue );
colors.push_back( SGCOLOR( aRedValue, aGreenValue, aBlueValue ) );
return;
}
@@ -238,16 +267,26 @@ bool SGCOLORS::WriteVRML( std::ostream& aFile, bool aReuseFlag )
bool SGCOLORS::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( nullptr == parentNode )
if( NULL == parentNode )
{
wxCHECK( m_Parent, false );
if( NULL == m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; m_aParent is NULL";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
SGNODE* np = m_Parent;
while( nullptr != np->GetParent() )
while( NULL != np->GetParent() )
np = np->GetParent();
if( np->WriteCache( aFile, nullptr ) )
if( np->WriteCache( aFile, NULL ) )
{
m_written = true;
return true;
@@ -256,12 +295,26 @@ bool SGCOLORS::WriteCache( std::ostream& aFile, SGNODE* parentNode )
return false;
}
wxCHECK( parentNode == m_Parent, false );
if( parentNode != m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; parentNode != m_aParent";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( !aFile.good() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad stream" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad stream";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -283,10 +336,20 @@ bool SGCOLORS::WriteCache( std::ostream& aFile, SGNODE* parentNode )
bool SGCOLORS::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
wxCHECK( colors.empty(), false );
if( !colors.empty() )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] non-empty node";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
size_t ncolors;
aFile.read( (char*) &ncolors, sizeof( size_t ) );
aFile.read( (char*)&ncolors, sizeof(size_t) );
SGCOLOR tmp;
if( aFile.fail() )
+10 -12
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,6 +23,7 @@
/**
* @file sg_colors.h
* defines an RGB color set for a scenegraph object
*/
#ifndef SG_COLORS_H
@@ -32,23 +32,23 @@
#include <vector>
#include "3d_cache/sg/sg_node.h"
/**
* Define an RGB color set for a scenegraph object.
*/
class SGCOLORS : public SGNODE
{
public:
std::vector< SGCOLOR > colors;
void unlinkChildNode( const SGNODE* aNode ) override;
void unlinkRefNode( const SGNODE* aNode ) override;
public:
SGCOLORS( SGNODE* aParent );
virtual ~SGCOLORS();
virtual bool SetParent( SGNODE* aParent, bool notify = true ) override;
void unlinkChildNode( const SGNODE* aNode ) noexcept override;
void unlinkRefNode( const SGNODE* aNode ) noexcept override;
SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller) noexcept override;
bool AddRefNode( SGNODE* aNode ) noexcept override;
bool AddChildNode( SGNODE* aNode ) noexcept override;
SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller) override;
bool AddRefNode( SGNODE* aNode ) override;
bool AddChildNode( SGNODE* aNode ) override;
bool GetColorList( size_t& aListSize, SGCOLOR*& aColorList );
void SetColorList( size_t aListSize, const SGCOLOR* aColorList );
@@ -60,8 +60,6 @@ public:
bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
std::vector< SGCOLOR > colors;
};
#endif // SG_COLORS_H
+6 -2
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -29,15 +28,18 @@ SGCOORDINDEX::SGCOORDINDEX( SGNODE* aParent ) : SGINDEX( aParent )
{
m_SGtype = S3D::SGTYPE_COORDINDEX;
if( nullptr != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
{
m_Parent->AddChildNode( this );
}
return;
}
SGCOORDINDEX::~SGCOORDINDEX()
{
return;
}
@@ -47,4 +49,6 @@ void SGCOORDINDEX::GatherCoordIndices( std::vector< int >& aIndexList )
return;
aIndexList.insert( aIndexList.end(), index.begin(), index.end() );
return;
}
+12 -8
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,6 +23,7 @@
/**
* @file sg_coordindex.h
* defines an coordinate index set for a scenegraph object
*/
#ifndef SG_COORDINDEX_H
@@ -32,12 +32,14 @@
#include "3d_cache/sg/sg_index.h"
/**
* An object to maintain a coordinate index list.
*
* Users must ensure that coordinate indices are specified as triplets (triangular faces)
* since no checking is performed. In instances where it is not possible to determine which
* side of the triangle is to be rendered (for example IGES entities) then the user must
* supply each triplet in both point orders.
* Class SGCOORDINDEX
* is a class which maintains a coordinate index list. Users
* must ensure that coordinate indices are specified as
* triplets (triangular faces) since no checking is performed.
* In instances where it is not possible to determine which
* side of the triangle is to be rendered (for example IGES
* entities) then the user must supply each triplet in both
* point orders.
*/
class SGCOORDINDEX : public SGINDEX
{
@@ -46,7 +48,9 @@ public:
virtual ~SGCOORDINDEX();
/**
* Add all coordinate indices to the given list in preparation for a normals calculation.
* Function GatherCoordIndices
* adds all coordinate indices to the given list
* in preparation for a normals calculation
*/
void GatherCoordIndices( std::vector< int >& aIndexList );
};
+107 -39
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -36,30 +35,37 @@ SGCOORDS::SGCOORDS( SGNODE* aParent ) : SGNODE( aParent )
{
m_SGtype = S3D::SGTYPE_COORDS;
if( nullptr != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
{
m_Parent = nullptr;
m_Parent = NULL;
wxLogTrace( MASK_3D_SG,
wxT( "%s:%s:%d * [BUG] inappropriate parent to SGCOORDS (type %s)" ),
__FILE__, __FUNCTION__, __LINE__, aParent->GetNodeType() );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] inappropriate parent to SGCOORDS (type ";
ostr << aParent->GetNodeType() << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
}
else if( nullptr != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
else if( NULL != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
{
m_Parent->AddChildNode( this );
}
return;
}
SGCOORDS::~SGCOORDS()
{
coords.clear();
return;
}
bool SGCOORDS::SetParent( SGNODE* aParent, bool notify )
{
if( nullptr != m_Parent )
if( NULL != m_Parent )
{
if( aParent == m_Parent )
return true;
@@ -68,14 +74,14 @@ bool SGCOORDS::SetParent( SGNODE* aParent, bool notify )
if( notify )
m_Parent->unlinkChildNode( this );
m_Parent = nullptr;
m_Parent = NULL;
if( nullptr == aParent )
if( NULL == aParent )
return true;
}
// only a SGFACESET may be parent to a SGCOORDS
if( nullptr != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
return false;
m_Parent = aParent;
@@ -87,41 +93,65 @@ bool SGCOORDS::SetParent( SGNODE* aParent, bool notify )
}
SGNODE* SGCOORDS::FindNode(const char *aNodeName, const SGNODE *aCaller) noexcept
SGNODE* SGCOORDS::FindNode(const char *aNodeName, const SGNODE *aCaller)
{
if( nullptr == aNodeName || 0 == aNodeName[0] )
return nullptr;
if( NULL == aNodeName || 0 == aNodeName[0] )
return NULL;
if( !m_Name.compare( aNodeName ) )
return this;
return nullptr;
return NULL;
}
void SGCOORDS::unlinkChildNode( const SGNODE* aCaller ) noexcept
void SGCOORDS::unlinkChildNode( const SGNODE* aCaller )
{
wxCHECK( aCaller, /* void */ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unexpected code branch; node should have no children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
void SGCOORDS::unlinkRefNode( const SGNODE* aCaller ) noexcept
void SGCOORDS::unlinkRefNode( const SGNODE* aCaller )
{
wxCHECK( aCaller, /* void */ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unexpected code branch; node should have no children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
bool SGCOORDS::AddRefNode( SGNODE* aNode ) noexcept
bool SGCOORDS::AddRefNode( SGNODE* aNode )
{
wxCHECK( aNode, false );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] this node does not accept children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
bool SGCOORDS::AddChildNode( SGNODE* aNode ) noexcept
bool SGCOORDS::AddChildNode( SGNODE* aNode )
{
wxCHECK( aNode, false );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] this node does not accept children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -132,7 +162,7 @@ bool SGCOORDS::GetCoordsList( size_t& aListSize, SGPOINT*& aCoordsList )
if( coords.empty() )
{
aListSize = 0;
aCoordsList = nullptr;
aCoordsList = NULL;
return false;
}
@@ -146,23 +176,27 @@ void SGCOORDS::SetCoordsList( size_t aListSize, const SGPOINT* aCoordsList )
{
coords.clear();
if( 0 == aListSize || nullptr == aCoordsList )
if( 0 == aListSize || NULL == aCoordsList )
return;
for( size_t i = 0; i < aListSize; ++i )
coords.push_back( aCoordsList[i] );
return;
}
void SGCOORDS::AddCoord( double aXValue, double aYValue, double aZValue )
{
coords.emplace_back( aXValue, aYValue, aZValue );
coords.push_back( SGPOINT( aXValue, aYValue, aZValue ) );
return;
}
void SGCOORDS::AddCoord( const SGPOINT& aPoint )
{
coords.push_back( aPoint );
return;
}
@@ -240,16 +274,26 @@ bool SGCOORDS::WriteVRML( std::ostream& aFile, bool aReuseFlag )
bool SGCOORDS::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( nullptr == parentNode )
if( NULL == parentNode )
{
wxCHECK( m_Parent, false );
if( NULL == m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; m_aParent is NULL";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
SGNODE* np = m_Parent;
while( nullptr != np->GetParent() )
while( NULL != np->GetParent() )
np = np->GetParent();
if( np->WriteCache( aFile, nullptr ) )
if( np->WriteCache( aFile, NULL ) )
{
m_written = true;
return true;
@@ -258,12 +302,26 @@ bool SGCOORDS::WriteCache( std::ostream& aFile, SGNODE* parentNode )
return false;
}
wxCHECK( parentNode == m_Parent, false );
if( parentNode != m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; parentNode != m_aParent";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( !aFile.good() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad stream" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad stream";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -285,10 +343,20 @@ bool SGCOORDS::WriteCache( std::ostream& aFile, SGNODE* parentNode )
bool SGCOORDS::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
wxCHECK( coords.empty(), false );
if( !coords.empty() )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] non-empty node";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
size_t npts;
aFile.read( (char*) &npts, sizeof( size_t ) );
aFile.read( (char*)&npts, sizeof(size_t) );
SGPOINT tmp;
if( aFile.fail() )
@@ -309,15 +377,15 @@ bool SGCOORDS::ReadCache( std::istream& aFile, SGNODE* parentNode )
bool SGCOORDS::CalcNormals( SGFACESET* callingNode, SGNODE** aPtr )
{
if( aPtr )
*aPtr = nullptr;
*aPtr = NULL;
if( nullptr == m_Parent || nullptr == callingNode )
if( NULL == m_Parent || NULL == callingNode )
return false;
// the parent and all references must have indices; collect all
// indices into one std::vector<>
std::vector< int > ilist;
SGNORMALS* np = nullptr;
SGNORMALS* np = NULL;
if( callingNode == m_Parent )
{
@@ -333,7 +401,7 @@ bool SGCOORDS::CalcNormals( SGFACESET* callingNode, SGNODE** aPtr )
++sB;
}
np = ( (SGFACESET*) m_Parent )->m_Normals;
np = ((SGFACESET*)m_Parent)->m_Normals;
if( !np )
np = new SGNORMALS( m_Parent );
+14 -15
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,6 +23,7 @@
/**
* @file sg_coords.h
* defines a vertex coordinate set for a scenegraph object
*/
#ifndef SG_COORDS_H
@@ -34,23 +34,23 @@
class SGFACESET;
/**
* Define a vertex coordinate set for a scenegraph object.
*/
class SGCOORDS : public SGNODE
{
public:
std::vector< SGPOINT > coords;
void unlinkChildNode( const SGNODE* aNode ) override;
void unlinkRefNode( const SGNODE* aNode ) override;
public:
SGCOORDS( SGNODE* aParent );
virtual ~SGCOORDS();
void unlinkChildNode( const SGNODE* aNode ) noexcept override;
void unlinkRefNode( const SGNODE* aNode ) noexcept override;
virtual bool SetParent( SGNODE* aParent, bool notify = true ) override;
SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller) noexcept override;
bool AddRefNode( SGNODE* aNode ) noexcept override;
bool AddChildNode( SGNODE* aNode ) noexcept override;
SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller) override;
bool AddRefNode( SGNODE* aNode ) override;
bool AddChildNode( SGNODE* aNode ) override;
bool GetCoordsList( size_t& aListSize, SGPOINT*& aCoordsList );
void SetCoordsList( size_t aListSize, const SGPOINT* aCoordsList );
@@ -58,18 +58,17 @@ public:
void AddCoord( const SGPOINT& aPoint );
/**
* Calculate normals for this coordinate list and sets the normals list in the
* parent #SGFACESET.
* Function CalcNormals
* calculates normals for this coordinate list and sets the
* normals list in the parent SGFACESET
*/
bool CalcNormals( SGFACESET* callingNode, SGNODE** aPtr = nullptr );
bool CalcNormals( SGFACESET* callingNode, SGNODE** aPtr = NULL );
void ReNameNodes( void ) override;
bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) override;
bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
std::vector< SGPOINT > coords;
};
#endif // SG_COORDS_H
+335 -190
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -34,33 +33,37 @@
#include "3d_cache/sg/sg_coordindex.h"
#include "3d_cache/sg/sg_helpers.h"
SGFACESET::SGFACESET( SGNODE* aParent ) : SGNODE( aParent )
{
m_SGtype = S3D::SGTYPE_FACESET;
m_Colors = nullptr;
m_Coords = nullptr;
m_CoordIndices = nullptr;
m_Normals = nullptr;
m_RColors = nullptr;
m_RCoords = nullptr;
m_RNormals = nullptr;
m_Colors = NULL;
m_Coords = NULL;
m_CoordIndices = NULL;
m_Normals = NULL;
m_RColors = NULL;
m_RCoords = NULL;
m_RNormals = NULL;
valid = false;
validated = false;
if( nullptr != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
{
m_Parent = nullptr;
m_Parent = NULL;
wxLogTrace( MASK_3D_SG,
wxT( "%s:%s:%d * [BUG] inappropriate parent to SGFACESET (type %s)" ),
__FILE__, __FUNCTION__, __LINE__,
aParent->GetNodeType() );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] inappropriate parent to SGFACESET (type ";
ostr << aParent->GetNodeType() << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
}
else if( nullptr != aParent && S3D::SGTYPE_SHAPE == aParent->GetNodeType() )
else if( NULL != aParent && S3D::SGTYPE_SHAPE == aParent->GetNodeType() )
{
m_Parent->AddChildNode( this );
}
return;
}
@@ -70,55 +73,57 @@ SGFACESET::~SGFACESET()
if( m_RColors )
{
m_RColors->delNodeRef( this );
m_RColors = nullptr;
m_RColors = NULL;
}
if( m_RCoords )
{
m_RCoords->delNodeRef( this );
m_RCoords = nullptr;
m_RCoords = NULL;
}
if( m_RNormals )
{
m_RNormals->delNodeRef( this );
m_RNormals = nullptr;
m_RNormals = NULL;
}
// delete owned objects
if( m_Colors )
{
m_Colors->SetParent( nullptr, false );
m_Colors->SetParent( NULL, false );
delete m_Colors;
m_Colors = nullptr;
m_Colors = NULL;
}
if( m_Coords )
{
m_Coords->SetParent( nullptr, false );
m_Coords->SetParent( NULL, false );
delete m_Coords;
m_Coords = nullptr;
m_Coords = NULL;
}
if( m_Normals )
{
m_Normals->SetParent( nullptr, false );
m_Normals->SetParent( NULL, false );
delete m_Normals;
m_Normals = nullptr;
m_Normals = NULL;
}
if( m_CoordIndices )
{
m_CoordIndices->SetParent( nullptr, false );
m_CoordIndices->SetParent( NULL, false );
delete m_CoordIndices;
m_CoordIndices = nullptr;
m_CoordIndices = NULL;
}
return;
}
bool SGFACESET::SetParent( SGNODE* aParent, bool notify )
{
if( nullptr != m_Parent )
if( NULL != m_Parent )
{
if( aParent == m_Parent )
return true;
@@ -127,14 +132,14 @@ bool SGFACESET::SetParent( SGNODE* aParent, bool notify )
if( notify )
m_Parent->unlinkChildNode( this );
m_Parent = nullptr;
m_Parent = NULL;
if( nullptr == aParent )
if( NULL == aParent )
return true;
}
// only a SGSHAPE may be parent to a SGFACESET
if( nullptr != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
return false;
m_Parent = aParent;
@@ -148,13 +153,13 @@ bool SGFACESET::SetParent( SGNODE* aParent, bool notify )
SGNODE* SGFACESET::FindNode(const char *aNodeName, const SGNODE *aCaller)
{
if( nullptr == aNodeName || 0 == aNodeName[0] )
return nullptr;
if( NULL == aNodeName || 0 == aNodeName[0] )
return NULL;
if( !m_Name.compare( aNodeName ) )
return this;
SGNODE* np = nullptr;
SGNODE* np = NULL;
if( m_Colors )
{
@@ -189,8 +194,8 @@ SGNODE* SGFACESET::FindNode(const char *aNodeName, const SGNODE *aCaller)
}
// query the parent if appropriate
if( aCaller == m_Parent || nullptr == m_Parent )
return nullptr;
if( aCaller == m_Parent || NULL == m_Parent )
return NULL;
return m_Parent->FindNode( aNodeName, this );
}
@@ -198,7 +203,7 @@ SGNODE* SGFACESET::FindNode(const char *aNodeName, const SGNODE *aCaller)
void SGFACESET::unlinkNode( const SGNODE* aNode, bool isChild )
{
if( nullptr == aNode )
if( NULL == aNode )
return;
valid = false;
@@ -208,25 +213,25 @@ void SGFACESET::unlinkNode( const SGNODE* aNode, bool isChild )
{
if( aNode == m_Colors )
{
m_Colors = nullptr;
m_Colors = NULL;
return;
}
if( aNode == m_Coords )
{
m_Coords = nullptr;
m_Coords = NULL;
return;
}
if( aNode == m_Normals )
{
m_Normals = nullptr;
m_Normals = NULL;
return;
}
if( aNode == m_CoordIndices )
{
m_CoordIndices = nullptr;
m_CoordIndices = NULL;
return;
}
}
@@ -235,46 +240,66 @@ void SGFACESET::unlinkNode( const SGNODE* aNode, bool isChild )
if( aNode == m_RColors )
{
delNodeRef( this );
m_RColors = nullptr;
m_RColors = NULL;
return;
}
if( aNode == m_RCoords )
{
delNodeRef( this );
m_RCoords = nullptr;
m_RCoords = NULL;
return;
}
if( aNode == m_RNormals )
{
delNodeRef( this );
m_RNormals = nullptr;
m_RNormals = NULL;
return;
}
}
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] unlinkNode() did not find its target" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unlinkNode() did not find its target";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return;
}
void SGFACESET::unlinkChildNode( const SGNODE* aNode )
{
unlinkNode( aNode, true );
return;
}
void SGFACESET::unlinkRefNode( const SGNODE* aNode )
{
unlinkNode( aNode, false );
return;
}
bool SGFACESET::addNode( SGNODE* aNode, bool isChild )
{
wxCHECK( aNode, false );
if( NULL == aNode )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL pointer passed for aNode";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
valid = false;
validated = false;
@@ -285,8 +310,12 @@ bool SGFACESET::addNode( SGNODE* aNode, bool isChild )
{
if( aNode != m_Colors && aNode != m_RColors )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] assigning multiple Colors nodes" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] assigning multiple Colors nodes";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -314,8 +343,12 @@ bool SGFACESET::addNode( SGNODE* aNode, bool isChild )
{
if( aNode != m_Coords && aNode != m_RCoords )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] assigning multiple Colors nodes" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] assigning multiple Coords nodes";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -343,8 +376,12 @@ bool SGFACESET::addNode( SGNODE* aNode, bool isChild )
{
if( aNode != m_Normals && aNode != m_RNormals )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] assigning multiple Normals nodes" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] assigning multiple Normals nodes";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -372,9 +409,12 @@ bool SGFACESET::addNode( SGNODE* aNode, bool isChild )
{
if( aNode != m_CoordIndices )
{
wxLogTrace( MASK_3D_SG,
wxT( "%s:%s:%d * [BUG] assigning multiple CoordIndex nodes" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] assigning multiple CoordIndex nodes";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -388,11 +428,16 @@ bool SGFACESET::addNode( SGNODE* aNode, bool isChild )
return true;
}
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] object type '%s' is not a valid type for "
"this object '%d'" ),
__FILE__, __FUNCTION__, __LINE__,
aNode->GetName(),
aNode->GetNodeType() );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] object '" << aNode->GetName();
ostr << "' (type " << aNode->GetNodeType();
ostr << ") is not a valid type for this object (" << aNode->GetNodeType() << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
@@ -432,12 +477,15 @@ void SGFACESET::ReNameNodes( void )
// rename all Normals and Indices
if( m_Normals )
m_Normals->ReNameNodes();
return;
}
bool SGFACESET::WriteVRML( std::ostream& aFile, bool aReuseFlag )
{
if( ( nullptr == m_Coords && nullptr == m_RCoords ) || ( nullptr == m_CoordIndices ) )
if( ( NULL == m_Coords && NULL == m_RCoords )
|| ( NULL == m_CoordIndices ) )
{
return false;
}
@@ -492,16 +540,26 @@ bool SGFACESET::WriteVRML( std::ostream& aFile, bool aReuseFlag )
bool SGFACESET::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( nullptr == parentNode )
if( NULL == parentNode )
{
wxCHECK( m_Parent, false );
if( NULL == m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; m_aParent is NULL";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
SGNODE* np = m_Parent;
while( nullptr != np->GetParent() )
while( NULL != np->GetParent() )
np = np->GetParent();
if( np->WriteCache( aFile, nullptr ) )
if( np->WriteCache( aFile, NULL ) )
{
m_written = true;
return true;
@@ -510,24 +568,38 @@ bool SGFACESET::WriteCache( std::ostream& aFile, SGNODE* parentNode )
return false;
}
wxCHECK( parentNode == m_Parent, false );
if( parentNode != m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; parentNode != m_aParent";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( !aFile.good() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad stream" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad stream";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
// check if any references are unwritten and swap parents if so
if( nullptr != m_RCoords && !m_RCoords->isWritten() )
if( NULL != m_RCoords && !m_RCoords->isWritten() )
m_RCoords->SwapParent( this );
if( nullptr != m_RNormals && !m_RNormals->isWritten() )
if( NULL != m_RNormals && !m_RNormals->isWritten() )
m_RNormals->SwapParent( this );
if( nullptr != m_RColors && !m_RColors->isWritten() )
if( NULL != m_RColors && !m_RColors->isWritten() )
m_RColors->SwapParent( this );
aFile << "[" << GetName() << "]";
@@ -539,35 +611,35 @@ bool SGFACESET::WriteCache( std::ostream& aFile, SGNODE* parentNode )
items[i] = 0;
i = 0;
if( nullptr != m_Coords )
if( NULL != m_Coords )
items[i] = true;
++i;
if( nullptr != m_RCoords )
if( NULL != m_RCoords )
items[i] = true;
++i;
if( nullptr != m_CoordIndices )
if( NULL != m_CoordIndices )
items[i] = true;
++i;
if( nullptr != m_Normals )
if( NULL != m_Normals )
items[i] = true;
++i;
if( nullptr != m_RNormals )
if( NULL != m_RNormals )
items[i] = true;
++i;
if( nullptr != m_Colors )
if( NULL != m_Colors )
items[i] = true;
++i;
if( nullptr != m_RColors )
if( NULL != m_RColors )
items[i] = true;
for( int jj = 0; jj < NITEMS; ++jj )
aFile.write( (char*) &items[jj], sizeof( bool ) );
aFile.write( (char*)&items[jj], sizeof(bool) );
if( items[0] )
m_Coords->WriteCache( aFile, this );
@@ -600,11 +672,16 @@ bool SGFACESET::WriteCache( std::ostream& aFile, SGNODE* parentNode )
bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( m_Coords || m_RCoords || m_CoordIndices || m_Colors || m_RColors || m_Normals
|| m_RNormals )
if( m_Coords || m_RCoords || m_CoordIndices
|| m_Colors || m_RColors
|| m_Normals || m_RNormals )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] non-empty node" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] non-empty node";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -613,14 +690,18 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
bool items[NITEMS];
for( int i = 0; i < NITEMS; ++i )
aFile.read( (char*) &items[i], sizeof( bool ) );
aFile.read( (char*)&items[i], sizeof(bool) );
if( ( items[0] && items[1] ) || ( items[3] && items[4] ) || ( items[5] && items[6] ) )
if( ( items[0] && items[1] ) || ( items[3] && items[4] )
|| ( items[5] && items[6] ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; multiple item definitions "
"at position %d" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<int>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; multiple item definitions at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -631,10 +712,13 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_COORDS != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child coords tag at "
"position %d" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<int>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad child coords tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -644,10 +728,13 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !m_Coords->ReadCache( aFile, this ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; corrupt data while "
"reading coords '%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data while reading coords '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -657,10 +744,13 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_COORDS != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref coords tag at "
"position %d" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<int>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad ref coords tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -669,20 +759,26 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !np )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; cannot find ref "
"coords '%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: cannot find ref coords '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( S3D::SGTYPE_COORDS != np->GetNodeType() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; type is not SGCOORDS "
"'%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: type is not SGCOORDS '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -695,10 +791,13 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_COORDINDEX != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad coord index tag at "
"position %d" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<int>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad coord index tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -708,10 +807,13 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !m_CoordIndices->ReadCache( aFile, this ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data while reading coord "
"index '%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data while reading coord index '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -721,10 +823,13 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_NORMALS != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child normals tag "
"at position %d" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<int>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad child normals tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -734,10 +839,13 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !m_Normals->ReadCache( aFile, this ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data while reading normals "
"'%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data while reading normals '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -747,10 +855,13 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_NORMALS != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref normals tag at "
"position %d" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<int>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad ref normals tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -759,19 +870,26 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !np )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt: cannot find ref normals "
"'%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: cannot find ref normals '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( S3D::SGTYPE_NORMALS != np->GetNodeType() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt: type is not SGNORMALS '%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: type is not SGNORMALS '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -784,10 +902,13 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_COLORS != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child colors tag "
"at position %d" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<int>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad child colors tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -797,10 +918,13 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !m_Colors->ReadCache( aFile, this ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data while reading colors "
"'%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data while reading colors '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -810,10 +934,13 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_COLORS != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref colors tag at "
"position %d" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<int>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad ref colors tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -822,20 +949,26 @@ bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !np )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: cannot find ref colors "
"'%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: cannot find ref colors '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( S3D::SGTYPE_COLORS != np->GetNodeType() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: type is not SGCOLORS "
"'%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: type is not SGCOLORS '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -858,14 +991,16 @@ bool SGFACESET::validate( void )
return valid;
// ensure we have at least coordinates and their normals
if( ( nullptr == m_Coords && nullptr == m_RCoords )
|| ( nullptr == m_Normals && nullptr == m_RNormals )
|| ( nullptr == m_CoordIndices ) )
if( (NULL == m_Coords && NULL == m_RCoords)
|| (NULL == m_Normals && NULL == m_RNormals)
|| (NULL == m_CoordIndices) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; no vertices, vertex indices, "
"or normals" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad model; no vertices, vertex indices, or normals";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
validated = true;
valid = false;
return false;
@@ -874,18 +1009,21 @@ bool SGFACESET::validate( void )
// check that there are >3 vertices
SGCOORDS* coords = m_Coords;
if( nullptr == coords )
if( NULL == coords )
coords = m_RCoords;
size_t nCoords = 0;
SGPOINT* lCoords = nullptr;
SGPOINT* lCoords = NULL;
coords->GetCoordsList( nCoords, lCoords );
if( nCoords < 3 )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; fewer than 3 vertices" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad model; fewer than 3 vertices";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
validated = true;
valid = false;
return false;
@@ -893,15 +1031,17 @@ bool SGFACESET::validate( void )
// check that nVertices is divisible by 3 (facets are triangles)
size_t nCIdx = 0;
int* lCIdx = nullptr;
int* lCIdx = NULL;
m_CoordIndices->GetIndices( nCIdx, lCIdx );
if( nCIdx < 3 || ( nCIdx % 3 > 0 ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; no vertex indices or not "
"multiple of 3" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad model; no vertex indices or not multiple of 3";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
validated = true;
valid = false;
return false;
@@ -912,10 +1052,12 @@ bool SGFACESET::validate( void )
{
if( lCIdx[i] < 0 || lCIdx[i] >= (int)nCoords )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; vertex index out of "
"bounds" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad model; vertex index out of bounds";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
validated = true;
valid = false;
return false;
@@ -924,22 +1066,23 @@ bool SGFACESET::validate( void )
// check that there are as many normals as vertices
size_t nNorms = 0;
SGVECTOR* lNorms = nullptr;
SGVECTOR* lNorms = NULL;
SGNORMALS* pNorms = m_Normals;
if( nullptr == pNorms )
if( NULL == pNorms )
pNorms = m_RNormals;
pNorms->GetNormalList( nNorms, lNorms );
if( nNorms != nCoords )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; number of normals (%ul) does "
"not match number of vertices (%ul)" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( nNorms ),
static_cast<unsigned long>( nCoords ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad model; number of normals (" << nNorms;
ostr << ") does not match number of vertices (" << nCoords << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
validated = true;
valid = false;
return false;
@@ -948,14 +1091,14 @@ bool SGFACESET::validate( void )
// if there are colors then ensure there are as many colors as vertices
SGCOLORS* pColors = m_Colors;
if( nullptr == pColors )
if( NULL == pColors )
pColors = m_RColors;
if( nullptr != pColors )
if( NULL != pColors )
{
// we must have at least as many colors as vertices
size_t nColor = 0;
SGCOLOR* pColor = nullptr;
SGCOLOR* pColor = NULL;
pColors->GetColorList( nColor, pColor );
}
@@ -969,6 +1112,8 @@ void SGFACESET::GatherCoordIndices( std::vector< int >& aIndexList )
{
if( m_CoordIndices )
m_CoordIndices->GatherCoordIndices( aIndexList );
return;
}
@@ -979,7 +1124,7 @@ bool SGFACESET::CalcNormals( SGNODE** aPtr )
if( m_RCoords )
coords = m_RCoords;
if( nullptr == coords || coords->coords.empty() )
if( NULL == coords || coords->coords.empty() )
return false;
if( m_Normals && !m_Normals->norms.empty( ) )
+28 -31
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,6 +23,7 @@
/**
* @file sg_faceset.h
* defines an indexed face set for a scenegraph
*/
@@ -40,18 +40,38 @@ class SGNORMALS;
class SGCOLORINDEX;
class SGCOORDINDEX;
/**
* Define an indexed face set for a scenegraph.
*/
class SGFACESET : public SGNODE
{
private:
bool valid;
bool validated;
void unlinkNode( const SGNODE* aNode, bool isChild );
bool addNode( SGNODE* aNode, bool isChild );
public:
// owned objects
SGCOLORS* m_Colors;
SGCOORDS* m_Coords;
SGCOORDINDEX* m_CoordIndices;
SGNORMALS* m_Normals;
// referenced objects
SGCOLORS* m_RColors;
SGCOORDS* m_RCoords;
SGNORMALS* m_RNormals;
void unlinkChildNode( const SGNODE* aNode ) override;
void unlinkRefNode( const SGNODE* aNode ) override;
// validate the data held by this face set
bool validate( void );
public:
SGFACESET( SGNODE* aParent );
virtual ~SGFACESET();
virtual bool SetParent( SGNODE* aParent, bool notify = true ) override;
SGNODE* FindNode( const char* aNodeName, const SGNODE* aCaller ) override;
SGNODE* FindNode( const char *aNodeName, const SGNODE *aCaller ) override;
bool AddRefNode( SGNODE* aNode ) override;
bool AddChildNode( SGNODE* aNode ) override;
@@ -64,34 +84,11 @@ public:
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
/**
* Add all internal coordinate indices to the given list in preparation for a normals
* calculation.
* Function GatherCoordIndices
* adds all internal coordinate indices to the given list
* in preparation for a normals calculation
*/
void GatherCoordIndices( std::vector< int >& aIndexList );
void unlinkChildNode( const SGNODE* aNode ) override;
void unlinkRefNode( const SGNODE* aNode ) override;
// validate the data held by this face set
bool validate( void );
// owned objects
SGCOLORS* m_Colors;
SGCOORDS* m_Coords;
SGCOORDINDEX* m_CoordIndices;
SGNORMALS* m_Normals;
// referenced objects
SGCOLORS* m_RColors;
SGCOORDS* m_RCoords;
SGNORMALS* m_RNormals;
private:
bool valid;
bool validated;
void unlinkNode( const SGNODE* aNode, bool isChild );
bool addNode( SGNODE* aNode, bool isChild );
};
/*
+109 -60
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -34,6 +33,7 @@
#include "3d_cache/sg/sg_node.h"
// formats a floating point number for text output to a VRML file
void S3D::FormatFloat( std::string& result, double value )
{
if( value < 1e-8 && value > -1e-8 )
@@ -49,9 +49,10 @@ void S3D::FormatFloat( std::string& result, double value )
result = out.str();
size_t p = result.find( '.' );
size_t p = result.find( "." );
// trim trailing 0 if appropriate
if( std::string::npos == p )
return;
@@ -59,26 +60,28 @@ void S3D::FormatFloat( std::string& result, double value )
if( std::string::npos == p )
{
while( '0' == *( result.rbegin() ) )
while( '0' == *(result.rbegin()) )
result.erase( result.size() - 1 );
return;
}
if( '0' != result.at( p - 1 ) )
if( '0' != result.at( p -1 ) )
return;
// trim all 0 to the left of 'p'
std::string tmp = result.substr( p );
result = result.substr( 0, p );
while( '0' == *( result.rbegin() ) )
while( '0' == *(result.rbegin()) )
result.erase( result.size() - 1 );
result.append( tmp );
return;
}
// format orientation data for VRML output
void S3D::FormatOrientation( std::string& result, const SGVECTOR& axis, double rotation )
{
double aX;
@@ -97,9 +100,11 @@ void S3D::FormatOrientation( std::string& result, const SGVECTOR& axis, double r
FormatFloat( tmp, rotation );
result.append( " " );
result.append( tmp );
return;
}
// format point data for VRML output
void S3D::FormatPoint( std::string& result, const SGPOINT& point )
{
FormatFloat( result, point.x );
@@ -112,9 +117,12 @@ void S3D::FormatPoint( std::string& result, const SGPOINT& point )
FormatFloat( tmp, point.z );
result.append( " " );
result.append( tmp );
return;
}
// format vector data for VRML output
void S3D::FormatVector( std::string& result, const SGVECTOR& aVector )
{
double X, Y, Z;
@@ -129,9 +137,12 @@ void S3D::FormatVector( std::string& result, const SGVECTOR& aVector )
FormatFloat( tmp, Z );
result.append( " " );
result.append( tmp );
return;
}
// format Color data for VRML output
void S3D::FormatColor( std::string& result, const SGCOLOR& aColor )
{
float R, G, B;
@@ -146,14 +157,16 @@ void S3D::FormatColor( std::string& result, const SGCOLOR& aColor )
FormatFloat( tmp, B );
result.append( " " );
result.append( tmp );
return;
}
bool S3D::WritePoint( std::ostream& aFile, const SGPOINT& aPoint )
{
aFile.write( (char*) &aPoint.x, sizeof( aPoint.x ) );
aFile.write( (char*) &aPoint.y, sizeof( aPoint.y ) );
aFile.write( (char*) &aPoint.z, sizeof( aPoint.z ) );
aFile.write( (char*)&aPoint.x, sizeof(aPoint.x) );
aFile.write( (char*)&aPoint.y, sizeof(aPoint.y) );
aFile.write( (char*)&aPoint.z, sizeof(aPoint.z) );
if( aFile.fail() )
return false;
@@ -166,9 +179,9 @@ bool S3D::WriteVector( std::ostream& aFile, const SGVECTOR& aVector )
{
double x, y, z;
aVector.GetVector( x, y, z );
aFile.write( (char*) &x, sizeof( double ) );
aFile.write( (char*) &y, sizeof( double ) );
aFile.write( (char*) &z, sizeof( double ) );
aFile.write( (char*)&x, sizeof(double) );
aFile.write( (char*)&y, sizeof(double) );
aFile.write( (char*)&z, sizeof(double) );
if( aFile.fail() )
return false;
@@ -181,9 +194,9 @@ bool S3D::WriteColor( std::ostream& aFile, const SGCOLOR& aColor )
{
float r, g, b;
aColor.GetColor( r, g, b );
aFile.write( (char*) &r, sizeof( float ) );
aFile.write( (char*) &g, sizeof( float ) );
aFile.write( (char*) &b, sizeof( float ) );
aFile.write( (char*)&r, sizeof(float) );
aFile.write( (char*)&g, sizeof(float) );
aFile.write( (char*)&b, sizeof(float) );
if( aFile.fail() )
return false;
@@ -199,10 +212,13 @@ S3D::SGTYPES S3D::ReadTag( std::istream& aFile, std::string& aName )
if( '[' != schar )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; missing left bracket at "
"position %d" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<int>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; missing left bracket at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return S3D::SGTYPE_END;
}
@@ -218,9 +234,12 @@ S3D::SGTYPES S3D::ReadTag( std::istream& aFile, std::string& aName )
if( schar != ']' )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; could not find right "
"bracket" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; could not find right bracket";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return S3D::SGTYPE_END;
}
@@ -230,9 +249,13 @@ S3D::SGTYPES S3D::ReadTag( std::istream& aFile, std::string& aName )
if( std::string::npos == upos )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; no underscore in name '%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; no underscore in name '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return S3D::SGTYPE_END;
}
@@ -256,9 +279,15 @@ S3D::SGTYPES S3D::ReadTag( std::istream& aFile, std::string& aName )
return types[i];
}
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; no node type matching '%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; no node type matching '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return S3D::SGTYPE_END;
}
@@ -266,9 +295,9 @@ S3D::SGTYPES S3D::ReadTag( std::istream& aFile, std::string& aName )
bool S3D::ReadPoint( std::istream& aFile, SGPOINT& aPoint )
{
aFile.read( (char*) &aPoint.x, sizeof( aPoint.x ) );
aFile.read( (char*) &aPoint.y, sizeof( aPoint.y ) );
aFile.read( (char*) &aPoint.z, sizeof( aPoint.z ) );
aFile.read( (char*)&aPoint.x, sizeof( aPoint.x ) );
aFile.read( (char*)&aPoint.y, sizeof( aPoint.y ) );
aFile.read( (char*)&aPoint.z, sizeof( aPoint.z ) );
if( aFile.fail() )
return false;
@@ -280,9 +309,9 @@ bool S3D::ReadPoint( std::istream& aFile, SGPOINT& aPoint )
bool S3D::ReadVector( std::istream& aFile, SGVECTOR& aVector )
{
double x, y, z;
aFile.read( (char*) &x, sizeof( double ) );
aFile.read( (char*) &y, sizeof( double ) );
aFile.read( (char*) &z, sizeof( double ) );
aFile.read( (char*)&x, sizeof(double) );
aFile.read( (char*)&y, sizeof(double) );
aFile.read( (char*)&z, sizeof(double) );
aVector.SetVector( x, y, z );
if( aFile.fail() )
@@ -295,9 +324,9 @@ bool S3D::ReadVector( std::istream& aFile, SGVECTOR& aVector )
bool S3D::ReadColor( std::istream& aFile, SGCOLOR& aColor )
{
float r, g, b;
aFile.read( (char*) &r, sizeof( float ) );
aFile.read( (char*) &g, sizeof( float ) );
aFile.read( (char*) &b, sizeof( float ) );
aFile.read( (char*)&r, sizeof(float) );
aFile.read( (char*)&g, sizeof(float) );
aFile.read( (char*)&b, sizeof(float) );
aColor.SetColor( r, g, b );
if( aFile.fail() )
@@ -307,7 +336,7 @@ bool S3D::ReadColor( std::istream& aFile, SGCOLOR& aColor )
}
bool S3D::degenerate( glm::dvec3* pts ) noexcept
bool S3D::degenerate( glm::dvec3* pts )
{
double dx, dy, dz;
@@ -347,19 +376,24 @@ static void calcTriad( glm::dvec3* pts, glm::dvec3& tri )
// normal * 2 * area
tri = glm::cross( pts[1] - pts[0], pts[2] - pts[0] );
return;
}
bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >& index,
std::vector< SGVECTOR >& norms )
bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords,
std::vector< int >& index, std::vector< SGVECTOR >& norms )
{
size_t vsize = coords.size();
if( vsize < 3 )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] invalid vertex set (fewer than 3 "
"vertices)" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid vertex set (fewer than 3 vertices)";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -368,16 +402,24 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
if( 0 != isize % 3 || index.empty() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] invalid index set (not multiple of 3)" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid index set (not multiple of 3)";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( !norms.empty() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] normals set is not empty" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] normals set is not empty";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -393,14 +435,15 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
p2 = index[i++];
p3 = index[i++];
if( p1 < 0 || p1 >= (int)vsize || p2 < 0 || p2 >= (int)vsize || p3 < 0 || p3 >= (int)vsize )
if( p1 < 0 || p1 >= (int)vsize || p2 < 0 || p2 >= (int)vsize ||
p3 < 0 || p3 >= (int)vsize )
{
#ifdef DEBUG
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid index set; index out of bounds";
wxLogTrace( MASK_3D_SG, wxT( "%s\n" ), ostr.str().c_str() );
#endif
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -420,7 +463,8 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
}
else
{
vmap.emplace( p1, std::list < glm::dvec3 >( 1, tri ) );
vmap.insert( std::pair < int, std::list < glm::dvec3 > >
( p1, std::list < glm::dvec3 >( 1, tri ) ) );
}
ip = vmap.find( p2 );
@@ -431,7 +475,8 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
}
else
{
vmap.emplace( p2, std::list < glm::dvec3 >( 1, tri ) );
vmap.insert( std::pair < int, std::list < glm::dvec3 > >
( p2, std::list < glm::dvec3 >( 1, tri ) ) );
}
ip = vmap.find( p3 );
@@ -442,7 +487,8 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
}
else
{
vmap.emplace( p3, std::list < glm::dvec3 >( 1, tri ) );
vmap.insert( std::pair < int, std::list < glm::dvec3 > >
( p3, std::list < glm::dvec3 >( 1, tri ) ) );
}
}
@@ -457,7 +503,7 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
// assign any skipped coordinates a normal of (0,0,1)
while( item > idx )
{
norms.emplace_back( 0, 0, 1 );
norms.push_back( SGVECTOR( 0, 0, 1 ) );
++idx;
}
@@ -471,7 +517,7 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
++sT;
}
norms.emplace_back( norm.x, norm.y, norm.z );
norms.push_back( SGVECTOR( norm.x, norm.y, norm.z ) );
++idx;
++sM;
@@ -479,9 +525,12 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
if( norms.size() != coords.size() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] number of normals does not equal number "
"of vertices" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] number of normals does not equal number of vertices";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
+121 -147
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,10 +23,10 @@
/**
* @file sg_helpers.h
*
* Define a number of macros to aid in repetitious code which is probably best expressed
* as a preprocessor macro rather than as a template. This header also declares a number
* of functions which are only of use within the sg_* classes.
* defines a number of macro functions to aid in repetitious code which
* is probably best expressed as a preprocessor macro rather than as
* a template. This header also declares a number of functions which are
* only of use within the sg_* classes.
*/
#ifndef SG_HELPERS_H
@@ -45,182 +44,151 @@ class SGNORMALS;
class SGCOORDS;
class SGCOORDINDEX;
// Function to drop references within an SGNODE
// The node being destroyed must remove itself from the object reference's
// backpointer list in order to avoid a segfault.
#define DROP_REFS( aType, aList ) \
do \
{ \
std::vector<aType*>::iterator sL = aList.begin(); \
std::vector<aType*>::iterator eL = aList.end(); \
while( sL != eL ) \
{ \
( (SGNODE*) *sL )->delNodeRef( this ); \
++sL; \
} \
aList.clear(); \
#define DROP_REFS( aType, aList ) do { \
std::vector< aType* >::iterator sL = aList.begin(); \
std::vector< aType* >::iterator eL = aList.end(); \
while( sL != eL ) { \
((SGNODE*)*sL)->delNodeRef( this ); \
++sL; \
} \
aList.clear(); \
} while( 0 )
// Function to delete owned objects within an SGNODE
// The owned object's parent is set to NULL before
// deletion to avoid a redundant 'unlinkChildNode' call.
#define DEL_OBJS( aType, aList ) \
do \
{ \
std::vector<aType*>::iterator sL = aList.begin(); \
std::vector<aType*>::iterator eL = aList.end(); \
while( sL != eL ) \
{ \
( (SGNODE*) *sL )->SetParent( nullptr, false ); \
delete *sL; \
++sL; \
} \
aList.clear(); \
#define DEL_OBJS( aType, aList ) do { \
std::vector< aType* >::iterator sL = aList.begin(); \
std::vector< aType* >::iterator eL = aList.end(); \
while( sL != eL ) { \
((SGNODE*)*sL)->SetParent( NULL, false ); \
delete *sL; \
++sL; \
} \
aList.clear(); \
} while( 0 )
// Function to unlink a child or reference node when that child or
// reference node is being destroyed.
#define UNLINK_NODE( aNodeID, aType, aNode, aOwnedList, aRefList, isChild ) \
do \
{ \
if( aNodeID == aNode->GetNodeType() ) \
{ \
std::vector<aType*>* oSL; \
std::vector<aType*>::iterator sL; \
std::vector<aType*>::iterator eL; \
if( isChild ) \
{ \
oSL = &aOwnedList; \
sL = oSL->begin(); \
eL = oSL->end(); \
while( sL != eL ) \
{ \
if( (SGNODE*) *sL == aNode ) \
{ \
oSL->erase( sL ); \
return; \
} \
++sL; \
} \
} \
else \
{ \
oSL = &aRefList; \
sL = oSL->begin(); \
eL = oSL->end(); \
while( sL != eL ) \
{ \
if( (SGNODE*) *sL == aNode ) \
{ \
delNodeRef( this ); \
oSL->erase( sL ); \
return; \
} \
++sL; \
} \
} \
return; \
} \
} while( 0 )
#define UNLINK_NODE( aNodeID, aType, aNode, aOwnedList, aRefList, isChild ) do { \
if( aNodeID == aNode->GetNodeType() ) { \
std::vector< aType* >* oSL; \
std::vector< aType* >::iterator sL; \
std::vector< aType* >::iterator eL; \
if( isChild ) { \
oSL = &aOwnedList; \
sL = oSL->begin(); \
eL = oSL->end(); \
while( sL != eL ) { \
if( (SGNODE*)*sL == aNode ) { \
oSL->erase( sL ); \
return; \
} \
++sL; \
} \
} else { \
oSL = &aRefList; \
sL = oSL->begin(); \
eL = oSL->end(); \
while( sL != eL ) { \
if( (SGNODE*)*sL == aNode ) { \
delNodeRef( this ); \
oSL->erase( sL ); \
return; \
} \
++sL; \
} \
} \
return; \
} } while( 0 )
// Function to check a node type, check for an existing reference,
// and add the node type to the reference list if applicable
#define ADD_NODE( aNodeID, aType, aNode, aOwnedList, aRefList, isChild ) \
do \
{ \
if( aNodeID == aNode->GetNodeType() ) \
{ \
std::vector<aType*>::iterator sL; \
sL = std::find( aOwnedList.begin(), aOwnedList.end(), aNode ); \
if( sL != aOwnedList.end() ) \
return true; \
sL = std::find( aRefList.begin(), aRefList.end(), aNode ); \
if( sL != aRefList.end() ) \
return true; \
if( isChild ) \
{ \
SGNODE* ppn = (SGNODE*) aNode->GetParent(); \
if( nullptr != ppn ) \
{ \
if( this != ppn ) \
{ \
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; \
std::cerr << " * [BUG] object '" << aNode->GetName(); \
std::cerr << "' has multiple parents '" << ppn->GetName() << "', '"; \
std::cerr << m_Name << "'\n"; \
return false; \
} \
} \
aOwnedList.push_back( (aType*) aNode ); \
aNode->SetParent( this, false ); \
} \
else \
{ \
/*if( nullptr == aNode->GetParent() ) { \
#define ADD_NODE( aNodeID, aType, aNode, aOwnedList, aRefList, isChild ) do { \
if( aNodeID == aNode->GetNodeType() ) { \
std::vector< aType* >::iterator sL; \
sL = std::find( aOwnedList.begin(), aOwnedList.end(), aNode ); \
if( sL != aOwnedList.end() ) return true; \
sL = std::find( aRefList.begin(), aRefList.end(), aNode ); \
if( sL != aRefList.end() ) return true; \
if( isChild ) { \
SGNODE* ppn = (SGNODE*)aNode->GetParent(); \
if( NULL != ppn ) { \
if( this != ppn ) { \
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; \
std::cerr << " * [BUG] object '" << aNode->GetName(); \
std::cerr << "' has multiple parents '" << ppn->GetName() << "', '"; \
std::cerr << m_Name << "'\n"; \
return false; \
} \
} \
aOwnedList.push_back( (aType*)aNode ); \
aNode->SetParent( this, false ); \
} else { \
/*if( NULL == aNode->GetParent() ) { \
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; \
std::cerr << " * [BUG] object '" << aNode->GetName(); \
std::cerr << "' has no parent\n"; \
std::cerr << " * [INFO] possible copy assignment or copy constructor bug\n"; \
return false; \
} */ \
aRefList.push_back( (aType*) aNode ); \
aNode->addNodeRef( this ); \
} \
return true; \
} \
} while( 0 )
} */ \
aRefList.push_back( (aType*)aNode ); \
aNode->addNodeRef( this ); \
} \
return true; \
} } while( 0 )
// Function to find a node object given a (non-unique) node name
#define FIND_NODE( aType, aName, aNodeList, aCallingNode ) \
do \
{ \
std::vector<aType*>::iterator sLA = aNodeList.begin(); \
std::vector<aType*>::iterator eLA = aNodeList.end(); \
SGNODE* psg = nullptr; \
while( sLA != eLA ) \
{ \
if( (SGNODE*) *sLA != aCallingNode ) \
{ \
psg = (SGNODE*) ( *sLA )->FindNode( aName, this ); \
if( nullptr != psg ) \
return psg; \
} \
++sLA; \
} \
} while( 0 )
#define FIND_NODE( aType, aName, aNodeList, aCallingNode ) do { \
std::vector< aType* >::iterator sLA = aNodeList.begin(); \
std::vector< aType* >::iterator eLA = aNodeList.end(); \
SGNODE* psg = NULL; \
while( sLA != eLA ) { \
if( (SGNODE*)*sLA != aCallingNode ) { \
psg = (SGNODE*) (*sLA)->FindNode( aName, this ); \
if( NULL != psg) \
return psg; \
} \
++sLA; \
} } while ( 0 )
namespace S3D
{
bool degenerate( glm::dvec3* pts ) noexcept;
bool degenerate( glm::dvec3* pts );
//
// Normals calculations from triangles
//
/*
* Take an array of 3D coordinates and its corresponding index set and calculates
* the normals assuming that indices are given in CCW order.
* Function CalcTriangleNormals
* takes an array of 3D coordinates and its corresponding index set and calculates
* the normals assuming that indices are given in CCW order. Care must be taken in
* using this function to ensure that:
* (a) all coordinates are indexed; unindexed coordinates are assigned normal(0,0,1);
* when dealing with VRML models which may list and reuse one large coordinate set it
* is necessary to gather all index sets and perform this operation only once.
* (b) index sets must represent triangles (multiple of 3 indices) and must not be
* degenerate - that is all indices and coordinates in a triad must be unique.
*
* Care must be taken in using this function to ensure that:
* -# All coordinates are indexed; unindexed coordinates are assigned normal(0,0,1);
* when dealing with VRML models which may list and reuse one large coordinate set it
* is necessary to gather all index sets and perform this operation only once.
* -# Index sets must represent triangles (multiple of 3 indices) and must not be
* degenerate, that is all indices and coordinates in a triad must be unique.
*
* @param coords is the array of 3D vertices.
* @param index is the array of 3x vertex indices (triads).
* @param norms is an empty array which holds the normals corresponding to each vector.
* @param coords is the array of 3D vertices
* @param index is the array of 3x vertex indices (triads)
* @param norms is an empty array which holds the normals corresponding to each vector
* @return true on success; otherwise false.
*/
bool CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >& index,
std::vector< SGVECTOR >& norms );
std::vector< SGVECTOR >& norms );
//
// VRML related functions
//
// formats a floating point number for text output to a VRML file
void FormatFloat( std::string& result, double value );
@@ -250,13 +218,19 @@ namespace S3D
// write out an RGB color
bool WriteColor( std::ostream& aFile, const SGCOLOR& aColor );
//
// Cache related READ functions
//
/**
* Read the text tag of a binary cache file which is the NodeTag and unique ID number combined.
* Function ReadTag
* reads the text tag of a binary cache file which is the
* NodeTag and unique ID number combined
*
* @param aFile is a binary file open for reading.
* @param aName will hold the tag name on successful return.
* @return will be the NodeType which the tag represents or S3D::SGTYPES::SGTYPE_END on
* failure.
* @param aFile is a binary file open for reading
* @param aName will hold the tag name on successful return
* @return will be the NodeType which the tag represents or
* S3D::SGTYPES::SGTYPE_END on failure
*/
S3D::SGTYPES ReadTag( std::istream& aFile, std::string& aName );
+109 -40
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -31,27 +30,33 @@
SGINDEX::SGINDEX( SGNODE* aParent ) : SGNODE( aParent )
{
if( nullptr != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
{
m_Parent = nullptr;
m_Parent = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] inappropriate parent to SGINDEX (type "
"'%d')" ),
__FILE__, __FUNCTION__, __LINE__,
aParent->GetNodeType() );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] inappropriate parent to SGINDEX (type ";
ostr << aParent->GetNodeType() << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
}
return;
}
SGINDEX::~SGINDEX()
{
index.clear();
return;
}
bool SGINDEX::SetParent( SGNODE* aParent, bool notify )
{
if( nullptr != m_Parent )
if( NULL != m_Parent )
{
if( aParent == m_Parent )
return true;
@@ -60,14 +65,14 @@ bool SGINDEX::SetParent( SGNODE* aParent, bool notify )
if( notify )
m_Parent->unlinkChildNode( this );
m_Parent = nullptr;
m_Parent = NULL;
if( nullptr == aParent )
if( NULL == aParent )
return true;
}
// only a SGFACESET may be parent to a SGINDEX and derived types
if( nullptr != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
return false;
m_Parent = aParent;
@@ -79,45 +84,65 @@ bool SGINDEX::SetParent( SGNODE* aParent, bool notify )
}
SGNODE* SGINDEX::FindNode(const char *aNodeName, const SGNODE *aCaller) noexcept
SGNODE* SGINDEX::FindNode(const char *aNodeName, const SGNODE *aCaller)
{
if( nullptr == aNodeName || 0 == aNodeName[0] )
return nullptr;
if( NULL == aNodeName || 0 == aNodeName[0] )
return NULL;
if( !m_Name.compare( aNodeName ) )
return this;
return nullptr;
return NULL;
}
void SGINDEX::unlinkChildNode( const SGNODE* aCaller ) noexcept
void SGINDEX::unlinkChildNode( const SGNODE* aCaller )
{
// Node should have no children or refs.
wxCHECK( false, /* void */ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unexpected code branch; node should have no children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
void SGINDEX::unlinkRefNode( const SGNODE* aCaller ) noexcept
void SGINDEX::unlinkRefNode( const SGNODE* aCaller )
{
// Node should have no children or refs.
wxCHECK( false, /* void */ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unexpected code branch; node should have no children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
bool SGINDEX::AddRefNode( SGNODE* aNode ) noexcept
bool SGINDEX::AddRefNode( SGNODE* aNode )
{
// Node should have no children or refs.
wxCHECK( false, false );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] this node does not accept children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
bool SGINDEX::AddChildNode( SGNODE* aNode ) noexcept
bool SGINDEX::AddChildNode( SGNODE* aNode )
{
// Node should have no children or refs.
wxCHECK( false, false );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] this node does not accept children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -128,7 +153,7 @@ bool SGINDEX::GetIndices( size_t& nIndices, int*& aIndexList )
if( index.empty() )
{
nIndices = 0;
aIndexList = nullptr;
aIndexList = NULL;
return false;
}
@@ -142,7 +167,7 @@ void SGINDEX::SetIndices( size_t nIndices, int* aIndexList )
{
index.clear();
if( 0 == nIndices || nullptr == aIndexList )
if( 0 == nIndices || NULL == aIndexList )
return;
for( size_t i = 0; i < nIndices; ++i )
@@ -155,6 +180,7 @@ void SGINDEX::SetIndices( size_t nIndices, int* aIndexList )
void SGINDEX::AddIndex( int aIndex )
{
index.push_back( aIndex );
return;
}
@@ -184,8 +210,17 @@ bool SGINDEX::writeCoordIndex( std::ostream& aFile )
{
size_t n = index.size();
wxCHECK_MSG( n % 3 == 0, false, wxT( "Coordinate index is not divisible by three (violates "
"triangle constraint)" ) );
if( n % 3 )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] coord index is not divisible by three (violates triangle constraint)";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
aFile << " coordIndex [\n ";
@@ -261,16 +296,26 @@ bool SGINDEX::writeIndexList( std::ostream& aFile )
bool SGINDEX::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( nullptr == parentNode )
if( NULL == parentNode )
{
wxCHECK( m_Parent, false );
if( NULL == m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; m_aParent is NULL";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
SGNODE* np = m_Parent;
while( nullptr != np->GetParent() )
while( NULL != np->GetParent() )
np = np->GetParent();
if( np->WriteCache( aFile, nullptr ) )
if( np->WriteCache( aFile, NULL ) )
{
m_written = true;
return true;
@@ -279,12 +324,26 @@ bool SGINDEX::WriteCache( std::ostream& aFile, SGNODE* parentNode )
return false;
}
wxCHECK( parentNode == m_Parent, false );
if( parentNode != m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; parentNode != m_aParent";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( !aFile.good() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad stream" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad stream";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -306,7 +365,17 @@ bool SGINDEX::WriteCache( std::ostream& aFile, SGNODE* parentNode )
bool SGINDEX::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
wxCHECK( index.empty(), false );
if( !index.empty() )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] non-empty node";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
size_t npts;
aFile.read( (char*)&npts, sizeof(size_t) );
@@ -317,7 +386,7 @@ bool SGINDEX::ReadCache( std::istream& aFile, SGNODE* parentNode )
for( size_t i = 0; i < npts; ++i )
{
aFile.read( (char*) &tmp, sizeof( int ) );
aFile.read( (char*)&tmp, sizeof(int) );
if( aFile.fail() )
return false;
+51 -52
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,6 +23,7 @@
/**
* @file sg_index.h
* defines a generic Index interface for a scenegraph object
*/
#ifndef SG_INDEX_H
@@ -32,59 +32,8 @@
#include <vector>
#include "3d_cache/sg/sg_node.h"
/**
* Define a generic index interface for a scenegraph object.
*/
class SGINDEX : public SGNODE
{
public:
SGINDEX( SGNODE* aParent );
virtual ~SGINDEX();
virtual bool SetParent( SGNODE* aParent, bool notify = true ) override;
SGNODE* FindNode(const char* aNodeName, const SGNODE* aCaller) noexcept override;
bool AddRefNode( SGNODE* aNode ) noexcept override;
bool AddChildNode( SGNODE* aNode ) noexcept override;
void unlinkChildNode( const SGNODE* aCaller ) noexcept override;
void unlinkRefNode( const SGNODE* aCaller ) noexcept override;
/**
* Retrieve the number of indices and a pointer to the list.
*
* @note The returned pointer may be invalidated by future operations on the SGNODE. The
* caller must make immediate use of the data and must not rely on the pointer's
* validity in the future.
*
* @param nIndices will hold the number of indices in the list.
* @param aIndexList will store a pointer to the data.
* @return true if there was available data (nIndices > 0) otherwise false.
*/
bool GetIndices( size_t& nIndices, int*& aIndexList );
/**
* Set the number of indices and creates a copy of the given index data.
*
* @param nIndices the number of indices to be stored.
* @param aIndexList the index data.
*/
void SetIndices( size_t nIndices, int* aIndexList );
/**
* Add a single index to the list.
*
* @param aIndex is the index to add.
*/
void AddIndex( int aIndex );
void ReNameNodes( void ) override;
bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) override;
bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
protected:
bool writeCoordIndex( std::ostream& aFile );
bool writeColorIndex( std::ostream& aFile );
@@ -93,6 +42,56 @@ protected:
public:
// for internal SG consumption only
std::vector< int > index;
void unlinkChildNode( const SGNODE* aCaller ) override;
void unlinkRefNode( const SGNODE* aCaller ) override;
public:
SGINDEX( SGNODE* aParent );
virtual ~SGINDEX();
virtual bool SetParent( SGNODE* aParent, bool notify = true ) override;
SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller) override;
bool AddRefNode( SGNODE* aNode ) override;
bool AddChildNode( SGNODE* aNode ) override;
/**
* Function GetIndices
* retrieves the number of indices and a pointer to
* the list. Note: the returned pointer may be invalidated
* by future operations on the SGNODE; the caller must make
* immediate use of the data and must not rely on the pointer's
* validity in the future.
*
* @param nIndices [out] will hold the number of indices in the list
* @param aIndexList [out] will store a pointer to the data
* @return true if there was available data (nIndices > 0) otherwise false
*/
bool GetIndices( size_t& nIndices, int*& aIndexList );
/**
* Function SetIndices
* sets the number of indices and creates a copy of the given index data.
*
* @param nIndices [in] the number of indices to be stored
* @param aIndexList [in] the index data
*/
void SetIndices( size_t nIndices, int* aIndexList );
/**
* Function AddIndex
* adds a single index to the list
*
* @param aIndex is the index to add
*/
void AddIndex( int aIndex );
void ReNameNodes( void ) override;
bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) override;
bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
};
#endif // SG_INDEX_H
+143 -50
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -32,7 +31,6 @@
#include "3d_cache/sg/sg_node.h"
#include "plugins/3dapi/c3dmodel.h"
static const std::string node_names[S3D::SGTYPE_END + 1] = {
"TXFM",
"APP",
@@ -50,7 +48,7 @@ static const std::string node_names[S3D::SGTYPE_END + 1] = {
static unsigned int node_counts[S3D::SGTYPE_END] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
char const* S3D::GetNodeTypeName( S3D::SGTYPES aType ) noexcept
char const* S3D::GetNodeTypeName( S3D::SGTYPES aType )
{
return node_names[aType].c_str();
}
@@ -70,15 +68,19 @@ static void getNodeName( S3D::SGTYPES nodeType, std::string& aName )
std::ostringstream ostr;
ostr << node_names[nodeType] << "_" << seqNum;
aName = ostr.str();
return;
}
SGNODE::SGNODE( SGNODE* aParent )
{
m_Parent = aParent;
m_Association = nullptr;
m_Association = NULL;
m_written = false;
m_SGtype = S3D::SGTYPE_END;
return;
}
@@ -88,7 +90,7 @@ SGNODE::~SGNODE()
m_Parent->unlinkChildNode( this );
if( m_Association )
*m_Association = nullptr;
*m_Association = NULL;
std::list< SGNODE* >::iterator sBP = m_BackPointers.begin();
std::list< SGNODE* >::iterator eBP = m_BackPointers.end();
@@ -98,16 +100,18 @@ SGNODE::~SGNODE()
(*sBP)->unlinkRefNode( this );
++sBP;
}
return;
}
S3D::SGTYPES SGNODE::GetNodeType( void ) const noexcept
S3D::SGTYPES SGNODE::GetNodeType( void ) const
{
return m_SGtype;
}
SGNODE* SGNODE::GetParent( void ) const noexcept
SGNODE* SGNODE::GetParent( void ) const
{
return m_Parent;
}
@@ -118,10 +122,10 @@ bool SGNODE::SwapParent( SGNODE* aNewParent )
if( aNewParent == m_Parent )
return true;
if( nullptr == aNewParent )
if( NULL == aNewParent )
return false;
if( nullptr == m_Parent )
if( NULL == m_Parent )
{
if( aNewParent->AddChildNode( this ) )
return true;
@@ -134,7 +138,7 @@ bool SGNODE::SwapParent( SGNODE* aNewParent )
SGNODE* oldParent = m_Parent;
m_Parent->unlinkChildNode( this );
m_Parent = nullptr;
m_Parent = NULL;
aNewParent->unlinkRefNode( this );
aNewParent->AddChildNode( this );
oldParent->AddRefNode( this );
@@ -152,16 +156,18 @@ const char* SGNODE::GetName( void )
}
void SGNODE::SetName( const char* aName )
void SGNODE::SetName( const char *aName )
{
if( nullptr == aName || 0 == aName[0] )
if( NULL == aName || 0 == aName[0] )
getNodeName( m_SGtype, m_Name );
else
m_Name = aName;
return;
}
const char* SGNODE::GetNodeTypeName( S3D::SGTYPES aNodeType ) const noexcept
const char * SGNODE::GetNodeTypeName( S3D::SGTYPES aNodeType ) const
{
return node_names[aNodeType].c_str();
}
@@ -169,7 +175,7 @@ const char* SGNODE::GetNodeTypeName( S3D::SGTYPES aNodeType ) const noexcept
void SGNODE::addNodeRef( SGNODE* aNode )
{
if( nullptr == aNode )
if( NULL == aNode )
return;
std::list< SGNODE* >::iterator np =
@@ -179,12 +185,13 @@ void SGNODE::addNodeRef( SGNODE* aNode )
return;
m_BackPointers.push_back( aNode );
return;
}
void SGNODE::delNodeRef( const SGNODE* aNode )
{
if( nullptr == aNode )
if( NULL == aNode )
return;
std::list< SGNODE* >::iterator np =
@@ -196,49 +203,110 @@ void SGNODE::delNodeRef( const SGNODE* aNode )
return;
}
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] delNodeRef() did not find its target, this "
"node type %d, referenced node type %d" ),
__FILE__, __FUNCTION__, __LINE__,
m_SGtype,
aNode->GetNodeType() );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] delNodeRef() did not find its target\n";
ostr << " * This Node Type: " << m_SGtype << ", Referenced node type: ";
ostr << aNode->GetNodeType() << "\n";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
void SGNODE::AssociateWrapper( SGNODE** aWrapperRef ) noexcept
void SGNODE::AssociateWrapper( SGNODE** aWrapperRef )
{
wxCHECK( aWrapperRef && *aWrapperRef == this, /* void */ );
if( NULL == aWrapperRef )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL handle";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
if( *aWrapperRef != this )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] handle value does not match this object's pointer";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
// if there is an existing association then break it and emit a warning
// just in case the behavior is undesired
if( m_Association )
{
*m_Association = nullptr;
*m_Association = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [WARNING] association being broken with "
"previous wrapper" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [WARNING] association being broken with previous wrapper";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
}
m_Association = aWrapperRef;
return;
}
void SGNODE::DisassociateWrapper( SGNODE** aWrapperRef ) noexcept
void SGNODE::DisassociateWrapper( SGNODE** aWrapperRef )
{
if( !m_Association )
return;
wxCHECK( aWrapperRef, /* void */ );
if( !aWrapperRef )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid handle value aWrapperRef";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
wxCHECK( *aWrapperRef == *m_Association && aWrapperRef == m_Association, /* void */ );
return;
}
m_Association = nullptr;
if( *aWrapperRef != *m_Association || aWrapperRef != m_Association )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] *aWrapperRef (" << *aWrapperRef;
ostr << ") does not match *m_Association (" << *m_Association << ") in type ";
ostr << node_names[ m_SGtype] << "\n";
ostr << " * [INFO] OR aWrapperRef(" << aWrapperRef << ") != m_Association(";
ostr << m_Association << ")\n";
ostr << " * [INFO] node name: " << GetName();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
m_Association = NULL;
return;
}
void SGNODE::ResetNodeIndex( void ) noexcept
void SGNODE::ResetNodeIndex( void )
{
for( int i = 0; i < (int)S3D::SGTYPE_END; ++i )
node_counts[i] = 1;
return;
}
@@ -246,7 +314,28 @@ bool S3D::GetMatIndex( MATLIST& aList, SGNODE* aNode, int& aIndex )
{
aIndex = 0;
wxCHECK( aNode && S3D::SGTYPE_APPEARANCE == aNode->GetNodeType(), false );
if( NULL == aNode || S3D::SGTYPE_APPEARANCE != aNode->GetNodeType() )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
ostr.str( "" );
if( NULL == aNode )
{
wxLogTrace( MASK_3D_SG, " * [BUG] aNode is NULL\n" );
}
else
{
ostr << " * [BUG] invalid node type (" << aNode->GetNodeType();
ostr << "), expected " << S3D::SGTYPE_APPEARANCE;
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
}
#endif
return false;
}
SGAPPEARANCE* node = (SGAPPEARANCE*)aNode;
@@ -260,7 +349,7 @@ bool S3D::GetMatIndex( MATLIST& aList, SGNODE* aNode, int& aIndex )
int idx = (int)aList.matorder.size();
aList.matorder.push_back( node );
aList.matmap.emplace( node, idx );
aList.matmap.insert( std::pair< SGAPPEARANCE const*, int >( node, idx ) );
aIndex = idx;
return true;
@@ -273,74 +362,78 @@ void S3D::INIT_SMATERIAL( SMATERIAL& aMaterial )
}
void S3D::INIT_SMESH( SMESH& aMesh ) noexcept
void S3D::INIT_SMESH( SMESH& aMesh )
{
aMesh = {};
}
void S3D::INIT_S3DMODEL( S3DMODEL& aModel ) noexcept
void S3D::INIT_S3DMODEL( S3DMODEL& aModel )
{
aModel = {};
}
void S3D::FREE_SMESH( SMESH& aMesh ) noexcept
void S3D::FREE_SMESH( SMESH& aMesh)
{
if( nullptr != aMesh.m_Positions )
if( NULL != aMesh.m_Positions )
{
delete [] aMesh.m_Positions;
aMesh.m_Positions = nullptr;
aMesh.m_Positions = NULL;
}
if( nullptr != aMesh.m_Normals )
if( NULL != aMesh.m_Normals )
{
delete [] aMesh.m_Normals;
aMesh.m_Normals = nullptr;
aMesh.m_Normals = NULL;
}
if( nullptr != aMesh.m_Texcoords )
if( NULL != aMesh.m_Texcoords )
{
delete [] aMesh.m_Texcoords;
aMesh.m_Texcoords = nullptr;
aMesh.m_Texcoords = NULL;
}
if( nullptr != aMesh.m_Color )
if( NULL != aMesh.m_Color )
{
delete [] aMesh.m_Color;
aMesh.m_Color = nullptr;
aMesh.m_Color = NULL;
}
if( nullptr != aMesh.m_FaceIdx )
if( NULL != aMesh.m_FaceIdx )
{
delete [] aMesh.m_FaceIdx;
aMesh.m_FaceIdx = nullptr;
aMesh.m_FaceIdx = NULL;
}
aMesh.m_VertexSize = 0;
aMesh.m_FaceIdxSize = 0;
aMesh.m_MaterialIdx = 0;
return;
}
void S3D::FREE_S3DMODEL( S3DMODEL& aModel )
{
if( nullptr != aModel.m_Materials )
if( NULL != aModel.m_Materials )
{
delete [] aModel.m_Materials;
aModel.m_Materials = nullptr;
aModel.m_Materials = NULL;
}
aModel.m_MaterialsSize = 0;
if( nullptr != aModel.m_Meshes )
if( NULL != aModel.m_Meshes )
{
for( unsigned int i = 0; i < aModel.m_MeshesSize; ++i )
FREE_SMESH( aModel.m_Meshes[i] );
delete [] aModel.m_Meshes;
aModel.m_Meshes = nullptr;
aModel.m_Meshes = NULL;
}
aModel.m_MeshesSize = 0;
return;
}
+121 -107
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,6 +23,7 @@
/**
* @file sg_node.h
* defines the base class of the intermediate scene graph NODE
*/
@@ -47,9 +47,10 @@ class SGAPPEARANCE;
namespace S3D
{
/**
* Return the name of the given type of node
* Function GetNodeTypeName
* returns the name of the given type of node
*/
char const* GetNodeTypeName( S3D::SGTYPES aType ) noexcept;
char const* GetNodeTypeName( S3D::SGTYPES aType );
struct MATLIST
{
@@ -60,67 +61,129 @@ namespace S3D
bool GetMatIndex( MATLIST& aList, SGNODE* aNode, int& aIndex );
void INIT_SMATERIAL( SMATERIAL& aMaterial );
void INIT_SMESH( SMESH& aMesh ) noexcept;
void INIT_S3DMODEL( S3DMODEL& aModel ) noexcept;
void INIT_SMESH( SMESH& aMesh );
void INIT_S3DMODEL( S3DMODEL& aModel );
void FREE_SMESH( SMESH& aMesh) noexcept;
void FREE_SMESH( SMESH& aMesh);
void FREE_S3DMODEL( S3DMODEL& aModel );
}
/**
* The base class of all Scene Graph nodes.
* Class SGNODE
* represents the base class of all Scene Graph nodes
*/
class SGNODE
{
private:
SGNODE** m_Association; // handle to the instance held by a wrapper
protected:
std::list< SGNODE* > m_BackPointers; // nodes which hold a reference to this
SGNODE* m_Parent; // pointer to parent node; may be NULL for top level transform
S3D::SGTYPES m_SGtype; // type of SG node
std::string m_Name; // name to use for referencing the entity by name
bool m_written; // set true when the object has been written after a ReNameNodes()
public:
/**
* Function unlinkChild
* removes references to an owned child; it is invoked by the child upon destruction
* to ensure that the parent has no invalid references.
*
* @param aNode is the child which is being deleted
*/
virtual void unlinkChildNode( const SGNODE* aNode ) = 0;
/**
* Function unlinkRef
* removes pointers to a referenced node; it is invoked by the referenced node
* upon destruction to ensure that the referring node has no invalid references.
*
* @param aNode is the node which is being deleted
*/
virtual void unlinkRefNode( const SGNODE* aNode ) = 0;
/**
* Function addNodeRef
* adds a pointer to a node which references, but does not own, this node.
* Such back-pointers are required to ensure that invalidated references
* are removed when a node is deleted
*
* @param aNode is the node holding a reference to this object
*/
void addNodeRef( SGNODE* aNode );
/**
* Function delNodeRef
* removes a pointer to a node which references, but does not own, this node.
*
* @param aNode is the node holding a reference to this object
*/
void delNodeRef( const SGNODE* aNode );
/**
* Function IsWritten
* returns true if the object had already been written to a
* cache file or VRML file; for internal use only.
*/
bool isWritten( void )
{
return m_written;
}
public:
SGNODE( SGNODE* aParent );
virtual ~SGNODE();
/**
* Return the type of this node instance.
* Function GetNodeType
* returns the type of this node instance
*/
S3D::SGTYPES GetNodeType( void ) const noexcept;
S3D::SGTYPES GetNodeType( void ) const;
/**
* Returns a pointer to the parent SGNODE of this object or NULL if the object has
* no parent (ie. top level transform).
* Function GetParent
* returns a pointer to the parent SGNODE of this object
* or NULL if the object has no parent (ie. top level transform)
*/
SGNODE* GetParent( void ) const noexcept;
SGNODE* GetParent( void ) const;
/**
* Set the parent #SGNODE of this object.
* Function SetParent
* sets the parent SGNODE of this object.
*
* @param aParent [in] is the desired parent node
* @return true if the operation succeeds; false if the given node is not allowed to
* be a parent to the derived object.
* @return true if the operation succeeds; false if
* the given node is not allowed to be a parent to
* the derived object.
*/
virtual bool SetParent( SGNODE* aParent, bool notify = true ) = 0;
/**
* Swap the ownership with the given parent.
* Function SwapParent
* swaps the ownership with the given parent. This operation
* may be required when reordering nodes for optimization.
*
* This operation may be required when reordering nodes for optimization.
*
* @param aNewParent will become the new parent to the object; it must be the same type
* as the parent of this instance.
* @param aNewParent [in] will become the new parent to the
* object; it must be the same type as the parent of this
* instance.
*/
bool SwapParent( SGNODE* aNewParent );
const char* GetName( void );
void SetName(const char *aName);
const char * GetNodeTypeName( S3D::SGTYPES aNodeType ) const noexcept;
const char * GetNodeTypeName( S3D::SGTYPES aNodeType ) const;
/**
* Search the tree of linked nodes and return a reference to the first node found with
* the given name.
* Function FindNode searches the tree of linked nodes and returns a
* reference to the first node found with the given name. The reference
* is then typically added to another node via AddRefNode().
*
* The reference is then typically added to another node via AddRefNode().
*
* @param aNodeName is the name of the node to search for.
* @param aCaller is a pointer to the node invoking this function.
* @return is a valid node pointer on success, otherwise NULL.
* @param aNodeName is the name of the node to search for
* @param aCaller is a pointer to the node invoking this function
* @return is a valid node pointer on success, otherwise NULL
*/
virtual SGNODE* FindNode( const char *aNodeName, const SGNODE *aCaller ) = 0;
@@ -129,108 +192,59 @@ public:
virtual bool AddChildNode( SGNODE* aNode ) = 0;
/**
* Associate this object with a handle to itself.
*
* The handle is typically held by an IFSG* wrapper and the pointer which it refers to
* is set to NULL upon destruction of this object. This mechanism provides a scheme
* by which a wrapper can be notified of the destruction of the object which it wraps.
* Function AssociateWrapper
* associates this object with a handle to itself; this handle
* is typically held by an IFSG* wrapper and the pointer which
* it refers to is set to NULL upon destruction of this object.
* This mechanism provides a scheme by which a wrapper can be
* notified of the destruction of the object which it wraps.
*/
void AssociateWrapper( SGNODE** aWrapperRef ) noexcept;
void AssociateWrapper( SGNODE** aWrapperRef );
/**
* Remove the association between an IFSG* wrapper object and this object.
* Function DisassociateWrapper
* removes the association between an IFSG* wrapper
* object and this object.
*/
void DisassociateWrapper( SGNODE** aWrapperRef ) noexcept;
void DisassociateWrapper( SGNODE** aWrapperRef );
/**
* Reset the global SG* node indices in preparation for write operations.
* Function ResetNodeIndex
* resets the global SG* node indices in preparation for
* Write() operations
*/
void ResetNodeIndex( void ) noexcept;
void ResetNodeIndex( void );
/**
* Rename a node and all its child nodes in preparation for write operations.
* Function ReNameNodes
* renames a node and all its child nodes in preparation for
* Write() operations
*/
virtual void ReNameNodes( void ) = 0;
/**
* Writes this node's data to a VRML file.
*
* This includes all data of child and referenced nodes.
* Function WriteVRML
* writes this node's data to a VRML file; this includes
* all data of child and referenced nodes.
*/
virtual bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) = 0;
/**
* Write this node's data to a binary cache file.
*
* The data includes all data of children and references to children. If this function
* is invoked by the user, parentNode must be set to NULL in order to ensure coherent data.
* Function WriteCache
* write's this node's data to a binary cache file; the data
* includes all data of children and references to children.
* If this function is invoked by the user, parentNode must be
* set to NULL in order to ensure coherent data.
*/
virtual bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) = 0;
/**
* Reads binary format data from a cache file.
*
* To read a cache file, open the file for reading and invoke this function from a new
* #SCENEGRAPH node.
* Function ReadCache
* Reads binary format data from a cache file. To read a cache file,
* open the file for reading and invoke this function from a new
* SCENEGRAPH node.
*/
virtual bool ReadCache( std::istream& aFile, SGNODE* parentNode ) = 0;
/**
* Remove references to an owned child.
*
* This is invoked by the child upon destruction to ensure that the parent has no
* invalid references.
*
* @param aNode is the child which is being deleted.
*/
virtual void unlinkChildNode( const SGNODE* aNode ) = 0;
/**
* Remove pointers to a referenced node.
*
* This is invoked by the referenced node upon destruction to ensure that the referring
* node has no invalid references.
*
* @param aNode is the node which is being deleted.
*/
virtual void unlinkRefNode( const SGNODE* aNode ) = 0;
/**
* Add a pointer to a node which references this node, but does not own.
*
* Such back-pointers are required to ensure that invalidated references are removed
* when a node is deleted.
*
* @param aNode is the node holding a reference to this object.
*/
void addNodeRef( SGNODE* aNode );
/**
* Remove a pointer to a node which references this node, but does not own.
*
* @param aNode is the node holding a reference to this object.
*/
void delNodeRef( const SGNODE* aNode );
/**
* Return true if the object had already been written to a cache file or VRML file
*
* For internal use only.
*/
bool isWritten( void ) noexcept
{
return m_written;
}
protected:
std::list< SGNODE* > m_BackPointers; ///< nodes which hold a reference to this.
SGNODE* m_Parent; ///< Pointer to parent node; may be NULL for top level transform.
S3D::SGTYPES m_SGtype; ///< Type of Scene Graph node.
std::string m_Name; ///< name to use for referencing the entity by name.
bool m_written; ///< Set to true when the object has been written after a ReNameNodes().
private:
SGNODE** m_Association; ///< Handle to the instance held by a wrapper.
};
#endif // SG_NODE_H
+103 -36
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -34,31 +33,37 @@ SGNORMALS::SGNORMALS( SGNODE* aParent ) : SGNODE( aParent )
{
m_SGtype = S3D::SGTYPE_NORMALS;
if( nullptr != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
{
m_Parent = nullptr;
m_Parent = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] inappropriate parent to SGNORMALS "
"(type %d)" ),
__FILE__, __FUNCTION__, __LINE__,
aParent->GetNodeType() );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] inappropriate parent to SGNORMALS (type ";
ostr << aParent->GetNodeType() << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
}
else if( nullptr != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
else if( NULL != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
{
m_Parent->AddChildNode( this );
}
return;
}
SGNORMALS::~SGNORMALS()
{
norms.clear();
return;
}
bool SGNORMALS::SetParent( SGNODE* aParent, bool notify )
{
if( nullptr != m_Parent )
if( NULL != m_Parent )
{
if( aParent == m_Parent )
return true;
@@ -67,14 +72,14 @@ bool SGNORMALS::SetParent( SGNODE* aParent, bool notify )
if( notify )
m_Parent->unlinkChildNode( this );
m_Parent = nullptr;
m_Parent = NULL;
if( nullptr == aParent )
if( NULL == aParent )
return true;
}
// only a SGFACESET may be parent to a SGNORMALS
if( nullptr != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
return false;
m_Parent = aParent;
@@ -86,41 +91,65 @@ bool SGNORMALS::SetParent( SGNODE* aParent, bool notify )
}
SGNODE* SGNORMALS::FindNode( const char* aNodeName, const SGNODE* aCaller ) noexcept
SGNODE* SGNORMALS::FindNode(const char *aNodeName, const SGNODE *aCaller)
{
if( nullptr == aNodeName || 0 == aNodeName[0] )
return nullptr;
if( NULL == aNodeName || 0 == aNodeName[0] )
return NULL;
if( !m_Name.compare( aNodeName ) )
return this;
return nullptr;
return NULL;
}
void SGNORMALS::unlinkChildNode( const SGNODE* aCaller ) noexcept
void SGNORMALS::unlinkChildNode( const SGNODE* aCaller )
{
wxCHECK( false, /* void */ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unexpected code branch; node should have no children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
void SGNORMALS::unlinkRefNode( const SGNODE* aCaller ) noexcept
void SGNORMALS::unlinkRefNode( const SGNODE* aCaller )
{
wxCHECK( false, /* void */ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unexpected code branch; node should have no children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return;
}
bool SGNORMALS::AddRefNode( SGNODE* aNode ) noexcept
bool SGNORMALS::AddRefNode( SGNODE* aNode )
{
wxCHECK( false, false );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] this node does not accept children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
bool SGNORMALS::AddChildNode( SGNODE* aNode ) noexcept
bool SGNORMALS::AddChildNode( SGNODE* aNode )
{
wxCHECK( false, false );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] this node does not accept children or refs";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -131,7 +160,7 @@ bool SGNORMALS::GetNormalList( size_t& aListSize, SGVECTOR*& aNormalList )
if( norms.empty() )
{
aListSize = 0;
aNormalList = nullptr;
aNormalList = NULL;
return false;
}
@@ -145,23 +174,27 @@ void SGNORMALS::SetNormalList( size_t aListSize, const SGVECTOR* aNormalList )
{
norms.clear();
if( 0 == aListSize || nullptr == aNormalList )
if( 0 == aListSize || NULL == aNormalList )
return;
for( int i = 0; i < (int)aListSize; ++i )
norms.push_back( aNormalList[i] );
return;
}
void SGNORMALS::AddNormal( double aXValue, double aYValue, double aZValue )
{
norms.emplace_back( aXValue, aYValue, aZValue );
norms.push_back( SGVECTOR( aXValue, aYValue, aZValue ) );
return;
}
void SGNORMALS::AddNormal( const SGVECTOR& aNormal )
{
norms.push_back( aNormal );
return;
}
@@ -233,16 +266,26 @@ bool SGNORMALS::WriteVRML( std::ostream& aFile, bool aReuseFlag )
bool SGNORMALS::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( nullptr == parentNode )
if( NULL == parentNode )
{
wxCHECK( m_Parent, false );
if( NULL == m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; m_aParent is NULL";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
SGNODE* np = m_Parent;
while( nullptr != np->GetParent() )
while( NULL != np->GetParent() )
np = np->GetParent();
if( np->WriteCache( aFile, nullptr ) )
if( np->WriteCache( aFile, NULL ) )
{
m_written = true;
return true;
@@ -251,12 +294,26 @@ bool SGNORMALS::WriteCache( std::ostream& aFile, SGNODE* parentNode )
return false;
}
wxCHECK( parentNode == m_Parent, false );
if( parentNode != m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; parentNode != m_aParent";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( !aFile.good() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad stream" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad stream";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -278,10 +335,20 @@ bool SGNORMALS::WriteCache( std::ostream& aFile, SGNODE* parentNode )
bool SGNORMALS::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
wxCHECK( norms.empty(), false );
if( !norms.empty() )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] non-empty node";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
size_t npts;
aFile.read( (char*) &npts, sizeof( size_t ) );
aFile.read( (char*)&npts, sizeof(size_t) );
SGVECTOR tmp;
if( aFile.fail() )
+10 -12
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,6 +23,7 @@
/**
* @file sg_normals.h
* defines a set of vertex normals for a scene graph object
*/
#ifndef SG_NORMALS_H
@@ -32,20 +32,23 @@
#include <vector>
#include "3d_cache/sg/sg_node.h"
/**
* Define a set of vertex normals for a scene graph object
*/
class SGNORMALS : public SGNODE
{
public:
std::vector< SGVECTOR > norms;
void unlinkChildNode( const SGNODE* aNode ) override;
void unlinkRefNode( const SGNODE* aNode ) override;
public:
SGNORMALS( SGNODE* aParent );
virtual ~SGNORMALS();
virtual bool SetParent( SGNODE* aParent, bool notify = true ) override;
SGNODE* FindNode( const char* aNodeName, const SGNODE* aCaller ) noexcept override;
bool AddRefNode( SGNODE* aNode ) noexcept override;
bool AddChildNode( SGNODE* aNode ) noexcept override;
SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller) override;
bool AddRefNode( SGNODE* aNode ) override;
bool AddChildNode( SGNODE* aNode ) override;
bool GetNormalList( size_t& aListSize, SGVECTOR*& aNormalList );
void SetNormalList( size_t aListSize, const SGVECTOR* aNormalList );
@@ -57,11 +60,6 @@ public:
bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
void unlinkChildNode( const SGNODE* aNode ) noexcept override;
void unlinkRefNode( const SGNODE* aNode ) noexcept override;
std::vector< SGVECTOR > norms;
};
#endif // SG_NORMALS_H
+249 -132
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -40,22 +39,29 @@
SGSHAPE::SGSHAPE( SGNODE* aParent ) : SGNODE( aParent )
{
m_SGtype = S3D::SGTYPE_SHAPE;
m_Appearance = nullptr;
m_RAppearance = nullptr;
m_FaceSet = nullptr;
m_RFaceSet = nullptr;
m_Appearance = NULL;
m_RAppearance = NULL;
m_FaceSet = NULL;
m_RFaceSet = NULL;
if( nullptr != aParent && S3D::SGTYPE_TRANSFORM != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_TRANSFORM != aParent->GetNodeType() )
{
m_Parent = nullptr;
m_Parent = NULL;
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] inappropriate parent to SGSHAPE (type %d)" ),
__FILE__, __FUNCTION__, __LINE__, aParent->GetNodeType() );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] inappropriate parent to SGSHAPE (type ";
ostr << aParent->GetNodeType() << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
}
else if( nullptr != aParent && S3D::SGTYPE_TRANSFORM == aParent->GetNodeType() )
else if( NULL != aParent && S3D::SGTYPE_TRANSFORM == aParent->GetNodeType() )
{
m_Parent->AddChildNode( this );
}
return;
}
@@ -65,35 +71,37 @@ SGSHAPE::~SGSHAPE()
if( m_RAppearance )
{
m_RAppearance->delNodeRef( this );
m_RAppearance = nullptr;
m_RAppearance = NULL;
}
if( m_RFaceSet )
{
m_RFaceSet->delNodeRef( this );
m_RFaceSet = nullptr;
m_RFaceSet = NULL;
}
// delete objects
if( m_Appearance )
{
m_Appearance->SetParent( nullptr, false );
m_Appearance->SetParent( NULL, false );
delete m_Appearance;
m_Appearance = nullptr;
m_Appearance = NULL;
}
if( m_FaceSet )
{
m_FaceSet->SetParent( nullptr, false );
m_FaceSet->SetParent( NULL, false );
delete m_FaceSet;
m_FaceSet = nullptr;
m_FaceSet = NULL;
}
return;
}
bool SGSHAPE::SetParent( SGNODE* aParent, bool notify )
{
if( nullptr != m_Parent )
if( NULL != m_Parent )
{
if( aParent == m_Parent )
return true;
@@ -102,14 +110,14 @@ bool SGSHAPE::SetParent( SGNODE* aParent, bool notify )
if( notify )
m_Parent->unlinkChildNode( this );
m_Parent = nullptr;
m_Parent = NULL;
if( nullptr == aParent )
if( NULL == aParent )
return true;
}
// only a SGTRANSFORM may be parent to a SGSHAPE
if( nullptr != aParent && S3D::SGTYPE_TRANSFORM != aParent->GetNodeType() )
if( NULL != aParent && S3D::SGTYPE_TRANSFORM != aParent->GetNodeType() )
return false;
m_Parent = aParent;
@@ -121,17 +129,17 @@ bool SGSHAPE::SetParent( SGNODE* aParent, bool notify )
}
SGNODE* SGSHAPE::FindNode( const char* aNodeName, const SGNODE* aCaller )
SGNODE* SGSHAPE::FindNode(const char *aNodeName, const SGNODE *aCaller)
{
if( nullptr == aNodeName || 0 == aNodeName[0] )
return nullptr;
if( NULL == aNodeName || 0 == aNodeName[0] )
return NULL;
if( !m_Name.compare( aNodeName ) )
return this;
SGNODE* tmp = nullptr;
SGNODE* tmp = NULL;
if( nullptr != m_Appearance )
if( NULL != m_Appearance )
{
tmp = m_Appearance->FindNode( aNodeName, this );
@@ -141,7 +149,7 @@ SGNODE* SGSHAPE::FindNode( const char* aNodeName, const SGNODE* aCaller )
}
}
if( nullptr != m_FaceSet )
if( NULL != m_FaceSet )
{
tmp = m_FaceSet->FindNode( aNodeName, this );
@@ -152,8 +160,8 @@ SGNODE* SGSHAPE::FindNode( const char* aNodeName, const SGNODE* aCaller )
}
// query the parent if appropriate
if( aCaller == m_Parent || nullptr == m_Parent )
return nullptr;
if( aCaller == m_Parent || NULL == m_Parent )
return NULL;
return m_Parent->FindNode( aNodeName, this );
}
@@ -161,20 +169,20 @@ SGNODE* SGSHAPE::FindNode( const char* aNodeName, const SGNODE* aCaller )
void SGSHAPE::unlinkNode( const SGNODE* aNode, bool isChild )
{
if( nullptr == aNode )
if( NULL == aNode )
return;
if( isChild )
{
if( aNode == m_Appearance )
{
m_Appearance = nullptr;
m_Appearance = NULL;
return;
}
if( aNode == m_FaceSet )
{
m_FaceSet = nullptr;
m_FaceSet = NULL;
return;
}
}
@@ -183,38 +191,58 @@ void SGSHAPE::unlinkNode( const SGNODE* aNode, bool isChild )
if( aNode == m_RAppearance )
{
delNodeRef( this );
m_RAppearance = nullptr;
m_RAppearance = NULL;
return;
}
if( aNode == m_RFaceSet )
{
delNodeRef( this );
m_RFaceSet = nullptr;
m_RFaceSet = NULL;
return;
}
}
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] unlinkNode() did not find its target" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] unlinkNode() did not find its target";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return;
}
void SGSHAPE::unlinkChildNode( const SGNODE* aNode )
{
unlinkNode( aNode, true );
return;
}
void SGSHAPE::unlinkRefNode( const SGNODE* aNode )
{
unlinkNode( aNode, false );
return;
}
bool SGSHAPE::addNode( SGNODE* aNode, bool isChild )
{
wxCHECK( aNode, false );
if( NULL == aNode )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL pointer passed for aNode";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( S3D::SGTYPE_APPEARANCE == aNode->GetNodeType() )
{
@@ -222,9 +250,12 @@ bool SGSHAPE::addNode( SGNODE* aNode, bool isChild )
{
if( aNode != m_Appearance && aNode != m_RAppearance )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] assigning multiple Appearance "
"nodes" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] assigning multiple Appearance nodes";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -252,8 +283,12 @@ bool SGSHAPE::addNode( SGNODE* aNode, bool isChild )
{
if( aNode != m_FaceSet && aNode != m_RFaceSet )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] assigning multiple FaceSet nodes" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] assigning multiple FaceSet nodes";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -275,9 +310,15 @@ bool SGSHAPE::addNode( SGNODE* aNode, bool isChild )
return true;
}
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] object %s is not a valid type for this "
"object (%d)" ),
__FILE__, __FUNCTION__, __LINE__, aNode->GetName(), aNode->GetNodeType() );
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] object '" << aNode->GetName();
ostr << "' is not a valid type for this object (" << aNode->GetNodeType() << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
@@ -310,12 +351,15 @@ void SGSHAPE::ReNameNodes( void )
// rename FaceSet
if( m_FaceSet )
m_FaceSet->ReNameNodes();
return;
}
bool SGSHAPE::WriteVRML( std::ostream& aFile, bool aReuseFlag )
{
if( !m_Appearance && !m_RAppearance && !m_FaceSet && !m_RFaceSet )
if( !m_Appearance && !m_RAppearance
&& !m_FaceSet && !m_RFaceSet )
{
return false;
}
@@ -358,16 +402,26 @@ bool SGSHAPE::WriteVRML( std::ostream& aFile, bool aReuseFlag )
bool SGSHAPE::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( nullptr == parentNode )
if( NULL == parentNode )
{
wxCHECK( m_Parent, false );
if( NULL == m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; m_aParent is NULL";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
SGNODE* np = m_Parent;
while( nullptr != np->GetParent() )
while( NULL != np->GetParent() )
np = np->GetParent();
if( np->WriteCache( aFile, nullptr ) )
if( np->WriteCache( aFile, NULL ) )
{
m_written = true;
return true;
@@ -376,21 +430,35 @@ bool SGSHAPE::WriteCache( std::ostream& aFile, SGNODE* parentNode )
return false;
}
wxCHECK( parentNode == m_Parent, false );
if( parentNode != m_Parent )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] corrupt data; parentNode != m_aParent";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( !aFile.good() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] bad stream" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad stream";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
// check if any references are unwritten and swap parents if so
if( nullptr != m_RAppearance && !m_RAppearance->isWritten() )
if( NULL != m_RAppearance && !m_RAppearance->isWritten() )
m_RAppearance->SwapParent(this);
if( nullptr != m_RFaceSet && !m_RFaceSet->isWritten() )
if( NULL != m_RFaceSet && !m_RFaceSet->isWritten() )
m_RFaceSet->SwapParent( this );
aFile << "[" << GetName() << "]";
@@ -402,23 +470,19 @@ bool SGSHAPE::WriteCache( std::ostream& aFile, SGNODE* parentNode )
items[i] = 0;
i = 0;
if( nullptr != m_Appearance )
if( NULL != m_Appearance )
items[i] = true;
++i;
if( nullptr != m_RAppearance )
if( NULL != m_RAppearance )
items[i] = true;
++i;
if( nullptr != m_FaceSet )
if( NULL != m_FaceSet )
items[i] = true;
++i;
if( nullptr != m_RFaceSet )
if( NULL != m_RFaceSet )
items[i] = true;
for( int jj = 0; jj < NITEMS; ++jj )
@@ -446,8 +510,17 @@ bool SGSHAPE::WriteCache( std::ostream& aFile, SGNODE* parentNode )
bool SGSHAPE::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
wxCHECK( m_Appearance == nullptr && m_RAppearance == nullptr && m_FaceSet == nullptr &&
m_RFaceSet == nullptr, false );
if( m_Appearance || m_RAppearance || m_FaceSet || m_RFaceSet )
{
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] non-empty node";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
#define NITEMS 4
bool items[NITEMS];
@@ -457,10 +530,13 @@ bool SGSHAPE::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( ( items[0] && items[1] ) || ( items[2] && items[3] ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; multiple item definitions "
"at position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; multiple item definitions at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -471,10 +547,13 @@ bool SGSHAPE::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_APPEARANCE != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child appearance "
"tag at position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad child apperance tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -484,9 +563,13 @@ bool SGSHAPE::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !m_Appearance->ReadCache( aFile, this ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data while reading appearance "
"'%s'" ),
__FILE__, __FUNCTION__, __LINE__, name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data while reading appearance '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -496,10 +579,13 @@ bool SGSHAPE::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_APPEARANCE != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref appearance tag "
"at position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad ref appearance tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -508,20 +594,26 @@ bool SGSHAPE::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !np )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: cannot find ref "
"appearance '%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: cannot find ref appearance '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( S3D::SGTYPE_APPEARANCE != np->GetNodeType() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: type is not "
"SGAPPEARANCE '%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: type is not SGAPPEARANCE '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -534,10 +626,13 @@ bool SGSHAPE::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_FACESET != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child face set tag "
"at position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad child face set tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -547,9 +642,13 @@ bool SGSHAPE::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !m_FaceSet->ReadCache( aFile, this ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data while reading face set "
"'%s'" ),
__FILE__, __FUNCTION__, __LINE__, name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data while reading face set '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -559,10 +658,13 @@ bool SGSHAPE::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( S3D::SGTYPE_FACESET != S3D::ReadTag( aFile, name ) )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref face set tag at "
"position %ul" ),
__FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( aFile.tellg() ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data; bad ref face set tag at position ";
ostr << aFile.tellg();
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -571,20 +673,26 @@ bool SGSHAPE::ReadCache( std::istream& aFile, SGNODE* parentNode )
if( !np )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: cannot find ref face "
"set '%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: cannot find ref face set '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
if( S3D::SGTYPE_FACESET != np->GetNodeType() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: type is not SGFACESET "
"'%s'" ),
__FILE__, __FUNCTION__, __LINE__,
name );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] corrupt data: type is not SGFACESET '";
ostr << name << "'";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return false;
}
@@ -600,8 +708,8 @@ bool SGSHAPE::ReadCache( std::istream& aFile, SGNODE* parentNode )
}
bool SGSHAPE::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
std::vector< SMESH >& meshes )
bool SGSHAPE::Prepare( const glm::dmat4* aTransform,
S3D::MATLIST& materials, std::vector< SMESH >& meshes )
{
SMESH m;
S3D::INIT_SMESH( m );
@@ -609,25 +717,28 @@ bool SGSHAPE::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
SGAPPEARANCE* pa = m_Appearance;
SGFACESET* pf = m_FaceSet;
if( nullptr == pa )
if( NULL == pa )
pa = m_RAppearance;
if( nullptr == pf )
if( NULL == pf )
pf = m_RFaceSet;
// no face sets = nothing to render, which is valid though pointless
if( nullptr == pf )
if( NULL == pf )
return true;
if( !pf->validate() )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; inconsistent data" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad model; inconsistent data";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return true;
}
if( nullptr == pa )
if( NULL == pa )
{
m.m_MaterialIdx = 0;
}
@@ -650,22 +761,22 @@ bool SGSHAPE::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
SGCOORDINDEX* vidx = pf->m_CoordIndices;
SGNORMALS* pn = pf->m_Normals;
if( nullptr == pc )
if( NULL == pc )
pc = pf->m_RColors;
if( nullptr == pv )
if( NULL == pv )
pv = pf->m_RCoords;
if( nullptr == pn )
if( NULL == pn )
pn = pf->m_RNormals;
// set the vertex points and indices
size_t nCoords = 0;
SGPOINT* pCoords = nullptr;
SGPOINT* pCoords = NULL;
pv->GetCoordsList( nCoords, pCoords );
size_t nColors = 0;
SGCOLOR* pColors = nullptr;
SGCOLOR* pColors = NULL;
if( pc )
{
@@ -674,18 +785,20 @@ bool SGSHAPE::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
if( nColors < nCoords )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; not enough colors per "
"vertex (%ul vs %ul)" ),
__FILE__, __FUNCTION__, __LINE__, static_cast<unsigned long>( nColors ),
static_cast<unsigned long>( nCoords ) );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad model; not enough colors per vertex (";
ostr << nColors << " vs " << nCoords << ")";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return true;
}
}
// set the vertex indices
size_t nvidx = 0;
int* lv = nullptr;
int* lv = NULL;
vidx->GetIndices( nvidx, lv );
// note: reduce the vertex set to include only the referenced vertices
@@ -699,21 +812,24 @@ bool SGSHAPE::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
if( mit == indexmap.end() )
{
indexmap.emplace( lv[i], vertices.size() );
indexmap.insert( std::pair< int, unsigned int >( lv[i], vertices.size() ) );
vertices.push_back( lv[i] );
}
}
if( vertices.size() < 3 )
{
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; not enough vertices" ),
__FILE__, __FUNCTION__, __LINE__ );
#ifdef DEBUG
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad model; not enough vertices";
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
#endif
return true;
}
// construct the final vertex/color list
SFVEC3F* lColors = nullptr;
SFVEC3F* lColors = NULL;
SFVEC3F* lCoords = new SFVEC3F[ vertices.size() ];
int ti;
@@ -723,6 +839,7 @@ bool SGSHAPE::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
m.m_Color = lColors;
}
if( pc )
{
for( size_t i = 0; i < vertices.size(); ++i )
@@ -760,7 +877,7 @@ bool SGSHAPE::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
// set the per-vertex normals
size_t nNorms = 0;
SGVECTOR* pNorms = nullptr;
SGVECTOR* pNorms = NULL;
double x, y, z;
pn->GetNormalList( nNorms, pNorms );
+23 -26
View File
@@ -2,7 +2,6 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,6 +23,7 @@
/**
* @file sg_shape.h
* defines a complex 3D shape for a scenegraph object
*/
@@ -36,33 +36,8 @@
class SGAPPEARANCE;
class SGFACESET;
/**
* Define a complex 3D shape for a scenegraph object.
*/
class SGSHAPE : public SGNODE
{
public:
SGSHAPE( SGNODE* aParent );
virtual ~SGSHAPE();
virtual bool SetParent( SGNODE* aParent, bool notify = true ) override;
SGNODE* FindNode(const char* aNodeName, const SGNODE* aCaller) override;
bool AddRefNode( SGNODE* aNode ) override;
bool AddChildNode( SGNODE* aNode ) override;
void ReNameNodes( void ) override;
bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) override;
bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
bool Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
std::vector< SMESH >& meshes );
void unlinkChildNode( const SGNODE* aNode ) override;
void unlinkRefNode( const SGNODE* aNode ) override;
private:
void unlinkNode( const SGNODE* aNode, bool isChild );
bool addNode( SGNODE* aNode, bool isChild );
@@ -75,6 +50,28 @@ public:
// referenced nodes
SGAPPEARANCE* m_RAppearance;
SGFACESET* m_RFaceSet;
void unlinkChildNode( const SGNODE* aNode ) override;
void unlinkRefNode( const SGNODE* aNode ) override;
public:
SGSHAPE( SGNODE* aParent );
virtual ~SGSHAPE();
virtual bool SetParent( SGNODE* aParent, bool notify = true ) override;
SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller) override;
bool AddRefNode( SGNODE* aNode ) override;
bool AddChildNode( SGNODE* aNode ) override;
void ReNameNodes( void ) override;
bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) override;
bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
bool Prepare( const glm::dmat4* aTransform,
S3D::MATLIST& materials, std::vector< SMESH >& meshes );
};
/*
File diff suppressed because it is too large Load Diff
-537
View File
@@ -1,537 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 2023 CERN
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef BOARD_ADAPTER_H
#define BOARD_ADAPTER_H
#include <array>
#include <vector>
#include "../3d_rendering/raytracing/accelerators/container_2d.h"
#include "../3d_rendering/raytracing/accelerators/container_3d.h"
#include "../3d_rendering/raytracing/shapes3D/bbox_3d.h"
#include <gal/3d/camera.h>
#include <3d_enums.h>
#include "../3d_cache/3d_cache.h"
#include "../common_ogl/ogl_attr_list.h"
#include "../3d_viewer/eda_3d_viewer_settings.h"
#include <layer_ids.h>
#include <pad.h>
#include <pcb_track.h>
#include <pcb_base_frame.h>
#include <pcb_text.h>
#include <pcb_textbox.h>
#include <pcb_table.h>
#include <pcb_shape.h>
#include <pcb_dimension.h>
#include <zone.h>
#include <footprint.h>
#include <reporter.h>
#include <dialogs/dialog_color_picker.h>
class COLOR_SETTINGS;
class PCB_TEXTBOX;
/// A type that stores a container of 2d objects for each layer id
typedef std::map<PCB_LAYER_ID, BVH_CONTAINER_2D*> MAP_CONTAINER_2D_BASE;
/// A type that stores polysets for each layer id
typedef std::map<PCB_LAYER_ID, SHAPE_POLY_SET*> MAP_POLY;
/// This defines the range that all coord will have to be rendered.
/// It will use this value to convert to a normalized value between
/// -(RANGE_SCALE_3D/2) .. +(RANGE_SCALE_3D/2)
#define RANGE_SCALE_3D 8.0f
/**
* Helper class to handle information needed to display 3D board.
*/
class BOARD_ADAPTER
{
public:
BOARD_ADAPTER();
~BOARD_ADAPTER();
/**
* Update the cache manager pointer.
*
* @param aCachePointer: the pointer to the 3D cache manager.
*/
void Set3dCacheManager( S3D_CACHE* aCacheMgr ) noexcept { m_3dModelManager = aCacheMgr; }
S3D_CACHE* Get3dCacheManager() const noexcept { return m_3dModelManager; }
/**
* Check if a layer is enabled.
*
* @param aLayer layer ID to get status.
*/
bool Is3dLayerEnabled( PCB_LAYER_ID aLayer,
const std::bitset<LAYER_3D_END>& aVisibilityFlags ) const;
/**
* Test if footprint should be displayed in relation to attributes and the flags.
*/
bool IsFootprintShown( FOOTPRINT_ATTR_T aFPAttributes ) const;
/**
* Set current board to be rendered.
*
* @param aBoard board to process.
*/
void SetBoard( BOARD* aBoard ) noexcept { m_board = aBoard; }
const BOARD* GetBoard() const noexcept { return m_board; }
void ReloadColorSettings() noexcept;
/**
* Build a color list which is used to store colors layers
*/
std::map<int, COLOR4D> GetLayerColors() const;
/**
* Build the copper color list used by the board editor, and store it in m_BoardEditorColors
*/
void GetBoardEditorCopperLayerColors( PCBNEW_SETTINGS* aCfg );
std::map<int, COLOR4D> GetDefaultColors() const;
void SetLayerColors( const std::map<int, COLOR4D>& aColors );
std::bitset<LAYER_3D_END> GetVisibleLayers() const;
std::bitset<LAYER_3D_END> GetDefaultVisibleLayers() const;
void SetVisibleLayers( const std::bitset<LAYER_3D_END>& aLayers );
/**
* Function to be called by the render when it need to reload the settings for the board.
*
* @param aStatusReporter the pointer for the status reporter.
* @param aWarningReporter pointer for the warning reporter.
*/
void InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
/**
* Board integer units To 3D units.
*
* @return the conversion factor to transform a position from the board to 3D units.
*/
double BiuTo3dUnits() const noexcept { return m_biuTo3Dunits; }
/**
* Get the board outline bounding box.
*
* @return the board bounding box in 3D units.
*/
const BBOX_3D& GetBBox() const noexcept { return m_boardBoundingBox; }
/**
* Get the board body thickness, including internal copper layers (in 3D units).
*/
float GetBoardBodyThickness() const noexcept { return m_boardBodyThickness3DU; }
/**
* Get the non copper layers thickness (in 3D units).
*/
float GetNonCopperLayerThickness() const noexcept { return m_nonCopperLayerThickness3DU; }
/**
* Get the copper layer thicknesses (in 3D units).
*/
float GetFrontCopperThickness() const noexcept { return m_frontCopperThickness3DU; }
float GetBackCopperThickness() const noexcept { return m_backCopperThickness3DU; }
/**
* Get the hole plating thickness (NB: in BOARD UNITS!).
*/
int GetHolePlatingThickness() const noexcept;
/**
* Get the board size.
*
* @return size in BIU units.
*/
VECTOR2I GetBoardSize() const noexcept { return m_boardSize; }
/**
* Get the board center.
*
* @return position in BIU units.
*/
VECTOR2I GetBoardPos() const noexcept { return m_boardPos; }
/**
* The board center position in 3D units.
*
* @return board center vector position in 3D units.
*/
const SFVEC3F& GetBoardCenter() const noexcept { return m_boardCenter; }
/**
* Get the position of the footprint in 3d integer units considering if it is flipped or not.
*
* @param aIsFlipped true for use in footprints on Front (top) layer, false
* if footprint is on back (bottom) layer.
* @return the Z position of 3D shapes, in 3D integer units.
*/
float GetFootprintZPos( bool aIsFlipped ) const ;
/**
* Get the current polygon of the epoxy board.
*
* @return the shape polygon
*/
const SHAPE_POLY_SET& GetBoardPoly() const noexcept { return m_board_poly; }
/**
* Get the technical color of a layer.
*
* @param aLayerId the layer to get the color information.
* @return the color in SFVEC3F format.
*/
SFVEC4F GetLayerColor( PCB_LAYER_ID aLayerId ) const;
/**
* Get the technical color of a layer.
*
* @param aItemId the item id to get the color information.
* @return the color in SFVEC3F format.
*/
SFVEC4F GetItemColor( int aItemId ) const;
/**
* @param[in] aColor is the color mapped.
* @return the color in SFVEC3F format
*/
SFVEC4F GetColor( const COLOR4D& aColor ) const;
SFVEC2F GetSphericalCoord( int i ) const;
/**
* Get the top z position.
*
* @param aLayerId layer id.
* @return position in 3D units.
*/
float GetLayerTopZPos( PCB_LAYER_ID aLayerId ) const noexcept
{
auto it = m_layerZcoordTop.find( aLayerId );
if( it != m_layerZcoordTop.end() )
return it->second;
else
return -( m_boardBodyThickness3DU / 2.0f );
}
/**
* Get the bottom z position.
*
* @param aLayerId layer id.
* @return position in 3D units.
*/
float GetLayerBottomZPos( PCB_LAYER_ID aLayerId ) const noexcept
{
auto it = m_layerZcoordBottom.find( aLayerId );
if( it != m_layerZcoordBottom.end() )
return it->second;
else
return -( m_boardBodyThickness3DU / 2.0f ) - m_backCopperThickness3DU;
}
/**
* Get the map of containers that have the objects per layer.
*
* @return the map containers of this board.
*/
const MAP_CONTAINER_2D_BASE& GetLayerMap() const noexcept { return m_layerMap; }
const BVH_CONTAINER_2D* GetPlatedPadsFront() const noexcept { return m_platedPadsFront; }
const BVH_CONTAINER_2D* GetPlatedPadsBack() const noexcept { return m_platedPadsBack; }
const BVH_CONTAINER_2D* GetOffboardPadsFront() const noexcept { return m_offboardPadsFront; }
const BVH_CONTAINER_2D* GetOffboardPadsBack() const noexcept { return m_offboardPadsBack; }
const MAP_CONTAINER_2D_BASE& GetLayerHoleMap() const noexcept { return m_layerHoleMap; }
const BVH_CONTAINER_2D& GetTH_IDs() const noexcept { return m_TH_IDs; }
const BVH_CONTAINER_2D& GetTH_ODs() const noexcept { return m_TH_ODs; }
/**
* Get through hole outside diameter 2D polygons.
*
* The outside diameter 2D polygon is the hole diameter plus the plating thickness.
*
* @return a container with through hold outside diameter 2D polygons.
*/
const SHAPE_POLY_SET& GetTH_ODPolys() const noexcept
{
return m_TH_ODPolys;
}
const BVH_CONTAINER_2D& GetViaAnnuli() const noexcept
{
return m_viaAnnuli;
}
const SHAPE_POLY_SET& GetViaAnnuliPolys() const noexcept
{
return m_viaAnnuliPolys;
}
const SHAPE_POLY_SET& GetNPTH_ODPolys() const noexcept
{
return m_NPTH_ODPolys;
}
/**
* @return a container with through hole via hole outside diameters.
*/
const BVH_CONTAINER_2D& GetViaTH_ODs() const noexcept
{
return m_viaTH_ODs;
}
const SHAPE_POLY_SET& GetViaTH_ODPolys() const noexcept
{
return m_viaTH_ODPolys;
}
unsigned int GetViaCount() const noexcept { return m_viaCount; }
unsigned int GetHoleCount() const noexcept { return m_holeCount; }
/**
* @return via hole average diameter dimension in 3D units.
*/
float GetAverageViaHoleDiameter() const noexcept { return m_averageViaHoleDiameter; }
/**
* @return the average diameter of through holes in 3D units.
*/
float GetAverageHoleDiameter() const noexcept { return m_averageHoleDiameter; }
/**
* @return average track width in 3D units.
*/
float GetAverageTrackWidth() const noexcept { return m_averageTrackWidth; }
/**
* @param aDiameter3DU diameter in 3DU.
* @return number of sides that should be used in a circle with \a aDiameter3DU.
*/
unsigned int GetCircleSegmentCount( float aDiameter3DU ) const;
/**
* @param aDiameterBIU diameter in board internal units.
* @return number of sides that should be used in circle with \a aDiameterBIU.
*/
unsigned int GetCircleSegmentCount( int aDiameterBIU ) const;
/**
* Get map of polygon's layers.
*
* @return the map with polygon's layers.
*/
const MAP_POLY& GetPolyMap() const noexcept { return m_layers_poly; }
const SHAPE_POLY_SET* GetFrontPlatedPadAndGraphicPolys()
{
return m_frontPlatedPadAndGraphicPolys;
}
const SHAPE_POLY_SET* GetBackPlatedPadAndGraphicPolys()
{
return m_backPlatedPadAndGraphicPolys;
}
const MAP_POLY& GetHoleIdPolysMap() const noexcept { return m_layerHoleIdPolys; }
const MAP_POLY& GetHoleOdPolysMap() const noexcept { return m_layerHoleOdPolys; }
private:
/**
* Create the board outline polygon.
*
* @return false if the outline could not be created
*/
bool createBoardPolygon( wxString* aErrorMsg );
void createLayers( REPORTER* aStatusReporter );
void destroyLayers();
// Helper functions to create the board
void createTrackWithMargin( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayer, int aMargin = 0 );
void createPadWithMargin( const PAD *aPad, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayer, const VECTOR2I& aMargin ) const;
void createPadWithHole( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer,
int aInflateValue );
void addPads( const FOOTPRINT* aFootprint, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId, bool aSkipPlatedPads, bool aSkipNonPlatedPads );
void addFootprintShapes( const FOOTPRINT* aFootprint, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId,
const std::bitset<LAYER_3D_END>& aVisibilityFlags );
void addText( const EDA_TEXT* aText, CONTAINER_2D_BASE* aDstContainer,
const BOARD_ITEM* aOwner );
void addShape( const PCB_SHAPE* aShape, CONTAINER_2D_BASE* aContainer,
const BOARD_ITEM* aOwner, PCB_LAYER_ID aLayer );
void addShape( const PCB_DIMENSION_BASE* aDimension, CONTAINER_2D_BASE* aDstContainer,
const BOARD_ITEM* aOwner );
void addShape( const PCB_TEXTBOX* aTextBox, CONTAINER_2D_BASE* aContainer,
const BOARD_ITEM* aOwner );
void addTable( const PCB_TABLE* aTable, CONTAINER_2D_BASE* aContainer,
const BOARD_ITEM* aOwner );
void addSolidAreasShapes( const ZONE* aZone, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId );
void createArcSegments( const VECTOR2I& aCentre, const VECTOR2I& aStart,
const EDA_ANGLE& aArcAngle, int aCircleToSegmentsCount, int aWidth,
CONTAINER_2D_BASE* aContainer, const BOARD_ITEM& aOwner );
void buildPadOutlineAsSegments( const PAD* aPad, PCB_LAYER_ID aLayer,
CONTAINER_2D_BASE* aDstContainer, int aWidth );
public:
static CUSTOM_COLORS_LIST g_SilkColors;
static CUSTOM_COLORS_LIST g_MaskColors;
static CUSTOM_COLORS_LIST g_PasteColors;
static CUSTOM_COLORS_LIST g_FinishColors;
static CUSTOM_COLORS_LIST g_BoardColors;
static KIGFX::COLOR4D g_DefaultBackgroundTop;
static KIGFX::COLOR4D g_DefaultBackgroundBot;
static KIGFX::COLOR4D g_DefaultSilkscreen;
static KIGFX::COLOR4D g_DefaultSolderMask;
static KIGFX::COLOR4D g_DefaultSolderPaste;
static KIGFX::COLOR4D g_DefaultSurfaceFinish;
static KIGFX::COLOR4D g_DefaultBoardBody;
static KIGFX::COLOR4D g_DefaultComments;
static KIGFX::COLOR4D g_DefaultECOs;
public:
EDA_3D_VIEWER_SETTINGS* m_Cfg;
bool m_IsBoardView;
bool m_MousewheelPanning;
bool m_IsPreviewer; ///< true if we're in a 3D preview panel, false
///< for the standard 3D viewer
SFVEC4F m_BgColorBot; ///< background bottom color
SFVEC4F m_BgColorTop; ///< background top color
SFVEC4F m_BoardBodyColor; ///< in realistic mode: FR4 board color
SFVEC4F m_SolderMaskColorBot; ///< in realistic mode: solder mask color ( bot )
SFVEC4F m_SolderMaskColorTop; ///< in realistic mode: solder mask color ( top )
SFVEC4F m_SolderPasteColor; ///< in realistic mode: solder paste color
SFVEC4F m_SilkScreenColorBot; ///< in realistic mode: SilkScreen color ( bot )
SFVEC4F m_SilkScreenColorTop; ///< in realistic mode: SilkScreen color ( top )
SFVEC4F m_CopperColor; ///< in realistic mode: copper color
SFVEC4F m_UserDrawingsColor;
SFVEC4F m_UserCommentsColor;
SFVEC4F m_ECO1Color;
SFVEC4F m_ECO2Color;
std::map<int, COLOR4D> m_ColorOverrides; ///< allows to override color scheme colors
std::map<int, COLOR4D> m_BoardEditorColors; ///< list of colors used by the board editor
private:
BOARD* m_board;
S3D_CACHE* m_3dModelManager;
COLOR_SETTINGS* m_colors;
VECTOR2I m_boardPos; ///< Board center position in board internal units.
VECTOR2I m_boardSize; ///< Board size in board internal units.
SFVEC3F m_boardCenter; ///< 3D center position of the board in 3D units.
BBOX_3D m_boardBoundingBox; ///< 3D bounding box of the board in 3D units.
MAP_POLY m_layers_poly; ///< Amalgamated polygon contours for various types
///< of items
SHAPE_POLY_SET* m_frontPlatedPadAndGraphicPolys;
SHAPE_POLY_SET* m_backPlatedPadAndGraphicPolys;
SHAPE_POLY_SET* m_frontPlatedCopperPolys;
SHAPE_POLY_SET* m_backPlatedCopperPolys;
MAP_POLY m_layerHoleOdPolys; ///< Hole outer diameters (per layer)
MAP_POLY m_layerHoleIdPolys; ///< Hole inner diameters (per layer)
SHAPE_POLY_SET m_NPTH_ODPolys; ///< NPTH outer diameters
SHAPE_POLY_SET m_TH_ODPolys; ///< PTH outer diameters
SHAPE_POLY_SET m_viaTH_ODPolys; ///< Via hole outer diameters
SHAPE_POLY_SET m_viaAnnuliPolys; ///< Via annular ring outer diameters
SHAPE_POLY_SET m_board_poly; ///< Board outline polygon.
MAP_CONTAINER_2D_BASE m_layerMap; ///< 2D elements for each layer.
MAP_CONTAINER_2D_BASE m_layerHoleMap; ///< Holes for each layer.
BVH_CONTAINER_2D* m_platedPadsFront;
BVH_CONTAINER_2D* m_platedPadsBack;
BVH_CONTAINER_2D* m_offboardPadsFront;
BVH_CONTAINER_2D* m_offboardPadsBack;
BVH_CONTAINER_2D m_TH_ODs; ///< List of PTH outer diameters
BVH_CONTAINER_2D m_TH_IDs; ///< List of PTH inner diameters
BVH_CONTAINER_2D m_viaAnnuli; ///< List of via annular rings
BVH_CONTAINER_2D m_viaTH_ODs; ///< List of via hole outer diameters
unsigned int m_copperLayersCount;
double m_biuTo3Dunits; ///< Scale factor to convert board internal units
///< to 3D units normalized between -1.0 and 1.0.
std::map<PCB_LAYER_ID, float> m_layerZcoordTop; ///< Top (End) Z position of each
///< layer in 3D units.
std::map<PCB_LAYER_ID, float> m_layerZcoordBottom; ///< Bottom (Start) Z position of
///< each layer in 3D units.
float m_frontCopperThickness3DU;
float m_backCopperThickness3DU;
float m_boardBodyThickness3DU;
float m_nonCopperLayerThickness3DU;
float m_solderPasteLayerThickness3DU;
unsigned int m_trackCount;
float m_averageTrackWidth;
unsigned int m_viaCount;
float m_averageViaHoleDiameter;
unsigned int m_holeCount;
float m_averageHoleDiameter;
/**
* Trace mask used to enable or disable debug output for this class. Output can be turned
* on by setting the WXTRACE environment variable to "KI_TRACE_EDA_CINFO3D_VISU". See the
* wxWidgets documentation on wxLogTrace for more information.
*/
static const wxChar* m_logTrace;
};
#endif // BOARD_ADAPTER_H
+517
View File
@@ -0,0 +1,517 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file cinfo3d_visu.cpp
* @brief Handles data related with the board to be visualized
*/
#include "../3d_rendering/ccamera.h"
#include "cinfo3d_visu.h"
#include <3d_rendering/3d_render_raytracing/shapes2D/cpolygon2d.h>
#include <class_board.h>
#include <3d_math.h>
#include "3d_fastmath.h"
#include <geometry/geometry_utils.h>
/**
* Trace mask used to enable or disable the trace output of this class.
* The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_EDA_CINFO3D_VISU". See the wxWidgets documentation on wxLogTrace for
* more information.
*/
const wxChar *CINFO3D_VISU::m_logTrace = wxT( "KI_TRACE_EDA_CINFO3D_VISU" );
CINFO3D_VISU G_null_CINFO3D_VISU;
CINFO3D_VISU::CINFO3D_VISU() :
m_currentCamera( m_trackBallCamera ),
m_trackBallCamera( RANGE_SCALE_3D )
{
wxLogTrace( m_logTrace, wxT( "CINFO3D_VISU::CINFO3D_VISU" ) );
m_board = NULL;
m_3d_model_manager = NULL;
m_3D_grid_type = GRID3D_NONE;
m_drawFlags.resize( FL_LAST, false );
m_render_engine = RENDER_ENGINE_OPENGL_LEGACY;
m_material_mode = MATERIAL_MODE_NORMAL;
m_boardPos = wxPoint();
m_boardSize = wxSize();
m_boardCenter = SFVEC3F( 0.0f );
m_boardBoudingBox.Reset();
m_layers_container2D.clear();
m_layers_holes2D.clear();
m_through_holes_inner.Clear();
m_through_holes_outer.Clear();
m_copperLayersCount = -1;
m_epoxyThickness3DU = 0.0f;
m_copperThickness3DU = 0.0f;
m_nonCopperLayerThickness3DU = 0.0f;
m_biuTo3Dunits = 1.0;
m_stats_nr_tracks = 0;
m_stats_nr_vias = 0;
m_stats_via_med_hole_diameter = 0.0f;
m_stats_nr_holes = 0;
m_stats_hole_med_diameter = 0.0f;
m_stats_track_med_width = 0.0f;
m_calc_seg_min_factor3DU = 0.0f;
m_calc_seg_max_factor3DU = 0.0f;
memset( m_layerZcoordTop, 0, sizeof( m_layerZcoordTop ) );
memset( m_layerZcoordBottom, 0, sizeof( m_layerZcoordBottom ) );
SetFlag( FL_USE_REALISTIC_MODE, true );
SetFlag( FL_MODULE_ATTRIBUTES_NORMAL, true );
SetFlag( FL_SHOW_BOARD_BODY, true );
SetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS, true );
SetFlag( FL_MODULE_ATTRIBUTES_NORMAL, true );
SetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT, true );
SetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL, true );
SetFlag( FL_ZONE, true );
SetFlag( FL_SILKSCREEN, true );
SetFlag( FL_SOLDERMASK, true );
m_BgColorBot = SFVEC3D( 0.4, 0.4, 0.5 );
m_BgColorTop = SFVEC3D( 0.8, 0.8, 0.9 );
m_BoardBodyColor = SFVEC3D( 0.4, 0.4, 0.5 );
m_SolderMaskColor = SFVEC3D( 0.1, 0.2, 0.1 );
m_SolderPasteColor = SFVEC3D( 0.4, 0.4, 0.4 );
m_SilkScreenColor = SFVEC3D( 0.9, 0.9, 0.9 );
m_CopperColor = SFVEC3D( 0.75, 0.61, 0.23 );
}
CINFO3D_VISU::~CINFO3D_VISU()
{
destroyLayers();
}
bool CINFO3D_VISU::Is3DLayerEnabled( PCB_LAYER_ID aLayer ) const
{
wxASSERT( aLayer < PCB_LAYER_ID_COUNT );
DISPLAY3D_FLG flg;
// see if layer needs to be shown
// check the flags
switch( aLayer )
{
case B_Adhes:
case F_Adhes:
flg = FL_ADHESIVE;
break;
case B_Paste:
case F_Paste:
flg = FL_SOLDERPASTE;
break;
case B_SilkS:
case F_SilkS:
flg = FL_SILKSCREEN;
break;
case B_Mask:
case F_Mask:
flg = FL_SOLDERMASK;
break;
case Dwgs_User:
case Cmts_User:
if( GetFlag( FL_USE_REALISTIC_MODE ) )
return false;
flg = FL_COMMENTS;
break;
case Eco1_User:
case Eco2_User:
if( GetFlag( FL_USE_REALISTIC_MODE ) )
return false;
flg = FL_ECO;
break;
case Edge_Cuts:
if( GetFlag( FL_SHOW_BOARD_BODY ) || GetFlag( FL_USE_REALISTIC_MODE ) )
return false;
return true;
break;
case Margin:
if( GetFlag( FL_USE_REALISTIC_MODE ) )
return false;
return true;
break;
case B_Cu:
case F_Cu:
return m_board->GetDesignSettings().IsLayerVisible( aLayer ) ||
GetFlag( FL_USE_REALISTIC_MODE );
break;
default:
// the layer is an internal copper layer, used the visibility
if( GetFlag( FL_SHOW_BOARD_BODY ) &&
(m_render_engine == RENDER_ENGINE_OPENGL_LEGACY) )
{
// Do not render internal layers if it is overlap with the board
// (on OpenGL render)
return false;
}
return m_board->GetDesignSettings().IsLayerVisible( aLayer );
}
// The layer has a flag, return the flag
return GetFlag( flg );
}
bool CINFO3D_VISU::GetFlag( DISPLAY3D_FLG aFlag ) const
{
wxASSERT( aFlag < FL_LAST );
return m_drawFlags[aFlag];
}
void CINFO3D_VISU::SetFlag( DISPLAY3D_FLG aFlag, bool aState )
{
wxASSERT( aFlag < FL_LAST );
m_drawFlags[aFlag] = aState;
}
bool CINFO3D_VISU::ShouldModuleBeDisplayed( MODULE_ATTR_T aModuleAttributs ) const
{
if( ( ( aModuleAttributs == MOD_DEFAULT ) &&
GetFlag( FL_MODULE_ATTRIBUTES_NORMAL ) ) ||
( ( ( aModuleAttributs & MOD_CMS) == MOD_CMS ) &&
GetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT ) ) ||
( ( ( aModuleAttributs & MOD_VIRTUAL) == MOD_VIRTUAL ) &&
GetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL ) ) )
{
return true;
}
return false;
}
// !TODO: define the actual copper thickness by user
#define COPPER_THICKNESS KiROUND( 0.035 * IU_PER_MM ) // for 35 um
#define TECH_LAYER_THICKNESS KiROUND( 0.04 * IU_PER_MM )
int CINFO3D_VISU::GetCopperThicknessBIU() const
{
return COPPER_THICKNESS;
}
unsigned int CINFO3D_VISU::GetNrSegmentsCircle( float aDiameter3DU ) const
{
wxASSERT( aDiameter3DU > 0.0f );
return GetNrSegmentsCircle( (int)( aDiameter3DU / m_biuTo3Dunits ) );
}
unsigned int CINFO3D_VISU::GetNrSegmentsCircle( int aDiameterBIU ) const
{
wxASSERT( aDiameterBIU > 0 );
// Require at least 3 segments for a circle
return std::max( GetArcToSegmentCount( aDiameterBIU / 2, ARC_HIGH_DEF, 360.0 ), 3 );
}
double CINFO3D_VISU::GetCircleCorrectionFactor( int aNrSides ) const
{
wxASSERT( aNrSides >= 3 );
return GetCircletoPolyCorrectionFactor( aNrSides );
}
void CINFO3D_VISU::InitSettings( REPORTER *aStatusTextReporter )
{
wxLogTrace( m_logTrace, wxT( "CINFO3D_VISU::InitSettings" ) );
// Calculates the board bounding box (board outlines + items)
// to ensure any item, even outside the board outlines can be seen
EDA_RECT bbbox = m_board->ComputeBoundingBox( false );
// Gives a non null size to avoid issues in zoom / scale calculations
if( ( bbbox.GetWidth() == 0 ) && ( bbbox.GetHeight() == 0 ) )
bbbox.Inflate( Millimeter2iu( 10 ) );
m_boardSize = bbbox.GetSize();
m_boardPos = bbbox.Centre();
wxASSERT( (m_boardSize.x > 0) && (m_boardSize.y > 0) );
m_boardPos.y = -m_boardPos.y; // The y coord is inverted in 3D viewer
m_copperLayersCount = m_board->GetCopperLayerCount();
// Ensure the board has 2 sides for 3D views, because it is hard to find
// a *really* single side board in the true life...
if( m_copperLayersCount < 2 )
m_copperLayersCount = 2;
// Calculate the convertion to apply to all positions.
m_biuTo3Dunits = RANGE_SCALE_3D / std::max( m_boardSize.x, m_boardSize.y );
m_epoxyThickness3DU = m_board->GetDesignSettings().GetBoardThickness() *
m_biuTo3Dunits;
// !TODO: use value defined by user (currently use default values by ctor
m_copperThickness3DU = COPPER_THICKNESS * m_biuTo3Dunits;
m_nonCopperLayerThickness3DU = TECH_LAYER_THICKNESS * m_biuTo3Dunits;
// Init Z position of each layer
// calculate z position for each copper layer
// Zstart = -m_epoxyThickness / 2.0 is the z position of the back (bottom layer) (layer id = 31)
// Zstart = +m_epoxyThickness / 2.0 is the z position of the front (top layer) (layer id = 0)
// all unused copper layer z position are set to 0
// ____==__________==________==______ <- Bottom = +m_epoxyThickness / 2.0,
// | | Top = Bottom + m_copperThickness
// |__________________________________|
// == == == == <- Bottom = -m_epoxyThickness / 2.0,
// Top = Bottom - m_copperThickness
unsigned int layer;
for( layer = 0; layer < m_copperLayersCount; ++layer )
{
m_layerZcoordBottom[layer] = m_epoxyThickness3DU / 2.0f -
(m_epoxyThickness3DU * layer / (m_copperLayersCount - 1) );
if( layer < (m_copperLayersCount / 2) )
m_layerZcoordTop[layer] = m_layerZcoordBottom[layer] + m_copperThickness3DU;
else
m_layerZcoordTop[layer] = m_layerZcoordBottom[layer] - m_copperThickness3DU;
}
#define layerThicknessMargin 1.1
const float zpos_offset = m_nonCopperLayerThickness3DU * layerThicknessMargin;
// Fill remaining unused copper layers and back layer zpos
// with -m_epoxyThickness / 2.0
for( ; layer < MAX_CU_LAYERS; layer++ )
{
m_layerZcoordBottom[layer] = -(m_epoxyThickness3DU / 2.0f);
m_layerZcoordTop[layer] = -(m_epoxyThickness3DU / 2.0f) - m_copperThickness3DU;
}
// This is the top of the copper layer thickness.
const float zpos_copperTop_back = m_layerZcoordTop[B_Cu];
const float zpos_copperTop_front = m_layerZcoordTop[F_Cu];
// calculate z position for each non copper layer
// Solder mask and Solder paste have the same Z position
for( int layer_id = MAX_CU_LAYERS; layer_id < PCB_LAYER_ID_COUNT; ++layer_id )
{
float zposTop;
float zposBottom;
switch( layer_id )
{
case B_Adhes:
zposBottom = zpos_copperTop_back - 2.0f * zpos_offset;
zposTop = zposBottom - m_nonCopperLayerThickness3DU;
break;
case F_Adhes:
zposBottom = zpos_copperTop_front + 2.0f * zpos_offset;
zposTop = zposBottom + m_nonCopperLayerThickness3DU;
break;
case B_Mask:
case B_Paste:
zposBottom = zpos_copperTop_back;
zposTop = zpos_copperTop_back - m_nonCopperLayerThickness3DU;
break;
case F_Mask:
case F_Paste:
zposTop = zpos_copperTop_front + m_nonCopperLayerThickness3DU;
zposBottom = zpos_copperTop_front;
break;
case B_SilkS:
zposBottom = zpos_copperTop_back - 1.0f * zpos_offset;
zposTop = zposBottom - m_nonCopperLayerThickness3DU;
break;
case F_SilkS:
zposBottom = zpos_copperTop_front + 1.0f * zpos_offset;
zposTop = zposBottom + m_nonCopperLayerThickness3DU;
break;
// !TODO: review
default:
zposTop = zpos_copperTop_front + (layer_id - MAX_CU_LAYERS + 3.0f) * zpos_offset;
zposBottom = zposTop - m_nonCopperLayerThickness3DU;
break;
}
m_layerZcoordTop[layer_id] = zposTop;
m_layerZcoordBottom[layer_id] = zposBottom;
}
m_boardCenter = SFVEC3F( m_boardPos.x * m_biuTo3Dunits,
m_boardPos.y * m_biuTo3Dunits,
0.0f );
SFVEC3F boardSize = SFVEC3F( m_boardSize.x * m_biuTo3Dunits,
m_boardSize.y * m_biuTo3Dunits,
0.0f );
boardSize /= 2.0f;
SFVEC3F boardMin = (m_boardCenter - boardSize);
SFVEC3F boardMax = (m_boardCenter + boardSize);
boardMin.z = m_layerZcoordTop[B_Adhes];
boardMax.z = m_layerZcoordTop[F_Adhes];
m_boardBoudingBox = CBBOX( boardMin, boardMax );
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_startCreateBoardPolyTime = GetRunningMicroSecs();
#endif
if( aStatusTextReporter )
aStatusTextReporter->Report( _( "Build board body" ) );
createBoardPolygon();
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_stopCreateBoardPolyTime = GetRunningMicroSecs();
unsigned stats_startCreateLayersTime = stats_stopCreateBoardPolyTime;
#endif
if( aStatusTextReporter )
aStatusTextReporter->Report( _( "Create layers" ) );
createLayers( aStatusTextReporter );
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_stopCreateLayersTime = GetRunningMicroSecs();
printf( "CINFO3D_VISU::InitSettings times\n" );
printf( " CreateBoardPoly: %.3f ms\n",
(float)( stats_stopCreateBoardPolyTime - stats_startCreateBoardPolyTime ) / 1e3 );
printf( " CreateLayers and holes: %.3f ms\n",
(float)( stats_stopCreateLayersTime - stats_startCreateLayersTime ) / 1e3 );
printf( "\n" );
#endif
}
void CINFO3D_VISU::createBoardPolygon()
{
m_board_poly.RemoveAllContours();
wxString errmsg;
if( !m_board->GetBoardPolygonOutlines( m_board_poly, /*allLayerHoles,*/ &errmsg ) )
{
errmsg.append( wxT( "\n\n" ) );
errmsg.append( _( "Cannot determine the board outline." ) );
wxLogMessage( errmsg );
}
}
float CINFO3D_VISU::GetModulesZcoord3DIU( bool aIsFlipped ) const
{
if( aIsFlipped )
{
if( GetFlag( FL_SOLDERPASTE ) )
return m_layerZcoordBottom[B_SilkS];
else
return m_layerZcoordBottom[B_Paste];
}
else
{
if( GetFlag( FL_SOLDERPASTE ) )
return m_layerZcoordTop[F_SilkS];
else
return m_layerZcoordTop[F_Paste];
}
}
void CINFO3D_VISU::CameraSetType( CAMERA_TYPE aCameraType )
{
switch( aCameraType )
{
case CAMERA_TRACKBALL:
m_currentCamera = m_trackBallCamera;
break;
default:
wxLogMessage( wxT( "CINFO3D_VISU::CameraSetType() error: unknown camera type %d" ),
(int)aCameraType );
break;
}
}
SFVEC3F CINFO3D_VISU::GetLayerColor( PCB_LAYER_ID aLayerId ) const
{
wxASSERT( aLayerId < PCB_LAYER_ID_COUNT );
const COLOR4D color = m_board->Colors().GetLayerColor( aLayerId );
return SFVEC3F( color.r, color.g, color.b );
}
SFVEC3F CINFO3D_VISU::GetItemColor( int aItemId ) const
{
return GetColor( m_board->Colors().GetItemColor( aItemId ) );
}
SFVEC3F CINFO3D_VISU::GetColor( COLOR4D aColor ) const
{
return SFVEC3F( aColor.r, aColor.g, aColor.b );
}
+677
View File
@@ -0,0 +1,677 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file cinfo3d_visu.h
* @brief Handles data related with the board to be visualized
*/
#ifndef CINFO3D_VISU_H
#define CINFO3D_VISU_H
#include <vector>
#include "../3d_rendering/3d_render_raytracing/accelerators/ccontainer2d.h"
#include "../3d_rendering/3d_render_raytracing/accelerators/ccontainer.h"
#include "../3d_rendering/3d_render_raytracing/shapes3D/cbbox.h"
#include "../3d_rendering/ccamera.h"
#include "../3d_rendering/ctrack_ball.h"
#include "../3d_enums.h"
#include "../3d_cache/3d_cache.h"
#include <layers_id_colors_and_visibility.h>
#include <class_pad.h>
#include <class_track.h>
#include <wx/gdicmn.h>
#include <pcb_base_frame.h>
#include <class_pcb_text.h>
#include <class_drawsegment.h>
#include <class_dimension.h>
#include <class_zone.h>
#include <class_module.h>
#include <reporter.h>
/// A type that stores a container of 2d objects for each layer id
typedef std::map< PCB_LAYER_ID, CBVHCONTAINER2D *> MAP_CONTAINER_2D;
/// A type that stores polysets for each layer id
typedef std::map< PCB_LAYER_ID, SHAPE_POLY_SET *> MAP_POLY;
/// This defines the range that all coord will have to be rendered.
/// It will use this value to convert to a normalized value between
/// -(RANGE_SCALE_3D/2) .. +(RANGE_SCALE_3D/2)
#define RANGE_SCALE_3D 8.0f
/**
* Class CINFO3D_VISU
* Helper class to handle information needed to display 3D board
*/
class CINFO3D_VISU
{
public:
CINFO3D_VISU();
~CINFO3D_VISU();
/**
* @brief Set3DCacheManager - Update the Cache manager pointer
* @param aCachePointer: the pointer to the 3d cache manager
*/
void Set3DCacheManager( S3D_CACHE *aCachePointer ) { m_3d_model_manager = aCachePointer; }
/**
* @brief Get3DCacheManager - Return the 3d cache manager pointer
* @return
*/
S3D_CACHE *Get3DCacheManager( ) const { return m_3d_model_manager; }
/**
* @brief GetFlag - get a configuration status of a flag
* @param aFlag: the flag to get the status
* @return true if flag is set, false if not
*/
bool GetFlag( DISPLAY3D_FLG aFlag ) const ;
/**
* @brief SetFlag - set the status of a flag
* @param aFlag: the flag to get the status
* @param aState: status to set
*/
void SetFlag( DISPLAY3D_FLG aFlag, bool aState );
/**
* @brief Is3DLayerEnabled - Check if a layer is enabled
* @param aLayer: layer ID to get status
* @return true if layer should be displayed, false if not
*/
bool Is3DLayerEnabled( PCB_LAYER_ID aLayer ) const;
/**
* @brief ShouldModuleBeDisplayed - Test if module should be displayed in
* relation to attributs and the flags
* @return true if module should be displayed, false if not
*/
bool ShouldModuleBeDisplayed( MODULE_ATTR_T aModuleAttributs ) const;
/**
* @brief SetBoard - Set current board to be rendered
* @param aBoard: board to process
*/
void SetBoard( BOARD *aBoard ) { m_board = aBoard; }
/**
* @brief GetBoard - Get current board to be rendered
* @return BOARD pointer
*/
const BOARD *GetBoard() const { return m_board; }
/**
* @brief InitSettings - Function to be called by the render when it need to
* reload the settings for the board.
* @param aStatusTextReporter: the pointer for the status reporter
*/
void InitSettings( REPORTER *aStatusTextReporter );
/**
* @brief BiuTo3Dunits - Board integer units To 3D units
* @return the conversion factor to transform a position from the board to 3d units
*/
double BiuTo3Dunits() const { return m_biuTo3Dunits; }
/**
* @brief GetBBox3DU - Get the bbox of the pcb board
* @return the board bbox in 3d units
*/
const CBBOX &GetBBox3DU() const { return m_boardBoudingBox; }
/**
* @brief GetEpoxyThickness3DU - Get the current epoxy thickness
* @return thickness in 3d unities
*/
float GetEpoxyThickness3DU() const { return m_epoxyThickness3DU; }
/**
* @brief GetNonCopperLayerThickness3DU - Get the current non copper layers thickness
* @return thickness in 3d unities of non copperlayers
*/
float GetNonCopperLayerThickness3DU() const { return m_nonCopperLayerThickness3DU; }
/**
* @brief GetCopperThickness3DU - Get the current copper layer thickness
* @return thickness in 3d unities of copperlayers
*/
float GetCopperThickness3DU() const { return m_copperThickness3DU; }
/**
* @brief GetCopperThicknessBIU - Get the current copper layer thickness
* @return thickness in board unities
*/
int GetCopperThicknessBIU() const;
/**
* @brief GetBoardSizeBIU - Get the board size
* @return size in BIU unities
*/
wxSize GetBoardSizeBIU() const { return m_boardSize; }
/**
* @brief GetBoardPosBIU - Get the board size
* @return size in BIU unities
*/
wxPoint GetBoardPosBIU() const { return m_boardPos; }
/**
* @brief GetBoardCenter - the board center position in 3d units
* @return board center vector position in 3d units
*/
const SFVEC3F &GetBoardCenter3DU() const { return m_boardCenter; }
/**
* @brief GetModulesZcoord3DIU - Get the position of the module in 3d integer units
* considering if it is flipped or not.
* @param aIsFlipped: true for use in modules on Front (top) layer, false
* if module is on back (bottom) layer
* @return the Z position of 3D shapes, in 3D integer units
*/
float GetModulesZcoord3DIU( bool aIsFlipped ) const ;
/**
* @brief CameraSetType - Set the camera type to use
* @param aCameraType: camera type to use in this canvas
*/
void CameraSetType( CAMERA_TYPE aCameraType );
/**
* @brief CameraGet - get current camera in use
* @return a camera
*/
CCAMERA &CameraGet() const { return m_currentCamera; }
/**
* @brief GridGet - get the current grid
* @return space type of the grid
*/
GRID3D_TYPE GridGet() const { return m_3D_grid_type; }
/**
* @brief GridSet - set the current grid
* @param aGridType = the type space of the grid
*/
void GridSet( GRID3D_TYPE aGridType ) { m_3D_grid_type = aGridType; }
/**
* @brief RenderEngineSet
* @param aRenderEngine = the render engine mode selected
*/
void RenderEngineSet( RENDER_ENGINE aRenderEngine ) { m_render_engine = aRenderEngine; }
/**
* @brief RenderEngineGet
* @return render engine on use
*/
RENDER_ENGINE RenderEngineGet() const { return m_render_engine; }
/**
* @brief MaterialModeSet
* @param aMaterialMode = the render material mode
*/
void MaterialModeSet( MATERIAL_MODE aMaterialMode ) { m_material_mode = aMaterialMode; }
/**
* @brief MaterialModeGet
* @return material rendering mode
*/
MATERIAL_MODE MaterialModeGet() const { return m_material_mode; }
/**
* @brief GetBoardPoly - Get the current polygon of the epoxy board
* @return the shape polygon
*/
const SHAPE_POLY_SET &GetBoardPoly() const { return m_board_poly; }
/**
* @brief GetLayerColor - get the technical color of a layer
* @param aLayerId: the layer to get the color information
* @return the color in SFVEC3F format
*/
SFVEC3F GetLayerColor( PCB_LAYER_ID aLayerId ) const;
/**
* @brief GetItemColor - get the technical color of a layer
* @param aItemId: the item id to get the color information
* @return the color in SFVEC3F format
*/
SFVEC3F GetItemColor( int aItemId ) const;
/**
* @brief GetColor
* @param aColor: the color mapped
* @return the color in SFVEC3F format
*/
SFVEC3F GetColor( COLOR4D aColor ) const;
/**
* @brief GetLayerTopZpos3DU - Get the top z position
* @param aLayerId: layer id
* @return position in 3D unities
*/
float GetLayerTopZpos3DU( PCB_LAYER_ID aLayerId ) const { return m_layerZcoordTop[aLayerId]; }
/**
* @brief GetLayerBottomZpos3DU - Get the bottom z position
* @param aLayerId: layer id
* @return position in 3D unities
*/
float GetLayerBottomZpos3DU( PCB_LAYER_ID aLayerId ) const { return m_layerZcoordBottom[aLayerId]; }
/**
* @brief GetMapLayers - Get the map of container that have the objects per layer
* @return the map containers of this board
*/
const MAP_CONTAINER_2D &GetMapLayers() const { return m_layers_container2D; }
/**
* @brief GetMapLayersHoles -Get the map of container that have the holes per layer
* @return the map containers of holes from this board
*/
const MAP_CONTAINER_2D &GetMapLayersHoles() const { return m_layers_holes2D; }
/**
* @brief GetThroughHole_Outer - Get the inflated ThroughHole container
* @return a container with holes
*/
const CBVHCONTAINER2D &GetThroughHole_Outer() const { return m_through_holes_outer; }
/**
* @brief GetThroughHole_Outer_poly -
* @return
*/
const SHAPE_POLY_SET &GetThroughHole_Outer_poly() const { return m_through_outer_holes_poly; }
/**
* @brief GetThroughHole_Outer_poly_NPTH -
* @return
*/
const SHAPE_POLY_SET &GetThroughHole_Outer_poly_NPTH() const {
return m_through_outer_holes_poly_NPTH; }
/**
* @brief GetThroughHole_Vias_Outer -
* @return a container with via THT holes only
*/
const CBVHCONTAINER2D &GetThroughHole_Vias_Outer() const { return m_through_holes_vias_outer; }
/**
* @brief GetThroughHole_Vias_Inner -
* @return a container with via THT holes only
*/
const CBVHCONTAINER2D &GetThroughHole_Vias_Inner() const { return m_through_holes_vias_inner; }
/**
* @brief GetThroughHole_Vias_Outer_poly -
* @return
*/
const SHAPE_POLY_SET &GetThroughHole_Vias_Outer_poly() const {
return m_through_outer_holes_vias_poly; }
/**
* @brief GetThroughHole_Vias_Inner_poly -
* @return
*/
const SHAPE_POLY_SET &GetThroughHole_Vias_Inner_poly() const {
return m_through_inner_holes_vias_poly; }
/**
* @brief GetThroughHole_Inner - Get the ThroughHole container
* @return a container with holes
*/
const CBVHCONTAINER2D &GetThroughHole_Inner() const { return m_through_holes_inner; }
/**
* @brief GetThroughHole_Inner_poly -
* @return
*/
const SHAPE_POLY_SET &GetThroughHole_Inner_poly() const { return m_through_inner_holes_poly; }
/**
* @brief GetStats_Nr_Vias - Get statistics of the nr of vias
* @return number of vias
*/
unsigned int GetStats_Nr_Vias() const { return m_stats_nr_vias; }
/**
* @brief GetStats_Nr_Holes - Get statistics of the nr of holes
* @return number of holes
*/
unsigned int GetStats_Nr_Holes() const { return m_stats_nr_holes; }
/**
* @brief GetStats_Med_Via_Hole_Diameter3DU - Average diameter of the via holes
* @return dimension in 3D units
*/
float GetStats_Med_Via_Hole_Diameter3DU() const { return m_stats_via_med_hole_diameter; }
/**
* @brief GetStats_Med_Hole_Diameter3DU - Average diameter of holes
* @return dimension in 3D units
*/
float GetStats_Med_Hole_Diameter3DU() const { return m_stats_hole_med_diameter; }
/**
* @brief GetStats_Med_Track_Width - Average width of the tracks
* @return dimensions in 3D units
*/
float GetStats_Med_Track_Width() const { return m_stats_track_med_width; }
/**
* @brief GetNrSegmentsCircle
* @param aDiameter3DU: diameter in 3DU
* @return number of sides that should be used in that circle
*/
unsigned int GetNrSegmentsCircle( float aDiameter3DU ) const;
/**
* @brief GetNrSegmentsCircle
* @param aDiameterBIU: diameter in board internal units
* @return number of sides that should be used in that circle
*/
unsigned int GetNrSegmentsCircle( int aDiameterBIU ) const;
/**
* @brief GetCircleCorrectionFactor - computes a angle correction
* factor used when creating circles
* @param aNrSides: the number of segments sides of the circle
* @return a factor to apply to contour creation
*/
double GetCircleCorrectionFactor( int aNrSides ) const;
/**
* @brief GetPolyMap - Get maps of polygons's layers
* @return the map with polygons's layers
*/
const MAP_POLY &GetPolyMap() const { return m_layers_poly; }
const MAP_POLY &GetPolyMapHoles_Inner() const { return m_layers_inner_holes_poly; }
const MAP_POLY &GetPolyMapHoles_Outer() const { return m_layers_outer_holes_poly; }
private:
void createBoardPolygon();
void createLayers( REPORTER *aStatusTextReporter );
void destroyLayers();
// Helper functions to create the board
COBJECT2D *createNewTrack( const TRACK* aTrack , int aClearanceValue ) const;
void createNewPad( const D_PAD* aPad,
CGENERICCONTAINER2D *aDstContainer,
wxSize aInflateValue ) const;
void createNewPadWithClearance( const D_PAD *aPad,
CGENERICCONTAINER2D *aDstContainer,
wxSize aClearanceValue ) const;
COBJECT2D *createNewPadDrill( const D_PAD* aPad, int aInflateValue );
void AddPadsShapesWithClearanceToContainer( const MODULE *aModule,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aInflateValue,
bool aSkipNPTHPadsWihNoCopper );
void AddGraphicsShapesWithClearanceToContainer( const MODULE *aModule,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aInflateValue );
void AddShapeWithClearanceToContainer( const TEXTE_PCB *aTextPCB,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aClearanceValue );
void AddShapeWithClearanceToContainer( const DRAWSEGMENT *aDrawSegment,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aClearanceValue );
void AddShapeWithClearanceToContainer( const DIMENSION *aDimension,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aClearanceValue );
void AddSolidAreasShapesToContainer( const ZONE_CONTAINER *aZoneContainer,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId );
void TransformArcToSegments( const wxPoint &aCentre,
const wxPoint &aStart,
double aArcAngle,
int aCircleToSegmentsCount,
int aWidth,
CGENERICCONTAINER2D *aDstContainer,
const BOARD_ITEM &aBoardItem );
void buildPadShapeThickOutlineAsSegments( const D_PAD *aPad,
CGENERICCONTAINER2D *aDstContainer,
int aWidth );
// Helper functions to create poly contours
void buildPadShapeThickOutlineAsPolygon( const D_PAD *aPad,
SHAPE_POLY_SET &aCornerBuffer,
int aWidth) const;
void transformPadsShapesWithClearanceToPolygon( const DLIST<D_PAD> &aPads,
PCB_LAYER_ID aLayer,
SHAPE_POLY_SET &aCornerBuffer,
int aInflateValue,
bool aSkipNPTHPadsWihNoCopper) const;
void transformGraphicModuleEdgeToPolygonSet( const MODULE *aModule,
PCB_LAYER_ID aLayer,
SHAPE_POLY_SET& aCornerBuffer ) const;
void buildPadShapePolygon( const D_PAD *aPad,
SHAPE_POLY_SET &aCornerBuffer,
wxSize aInflateValue,
int aSegmentsPerCircle,
double aCorrectionFactor ) const;
public:
SFVEC3D m_BgColorBot; ///< background bottom color
SFVEC3D m_BgColorTop; ///< background top color
SFVEC3D m_BoardBodyColor; ///< in realistic mode: FR4 board color
SFVEC3D m_SolderMaskColor; ///< in realistic mode: solder mask color
SFVEC3D m_SolderPasteColor; ///< in realistic mode: solder paste color
SFVEC3D m_SilkScreenColor; ///< in realistic mode: SilkScreen color
SFVEC3D m_CopperColor; ///< in realistic mode: copper color
private:
/// Current board
BOARD *m_board;
/// pointer to the 3d model manager
S3D_CACHE *m_3d_model_manager;
// Render options
/// options flags to render the board
std::vector< bool > m_drawFlags;
/// Stores the current grid type
GRID3D_TYPE m_3D_grid_type;
/// render engine currently on use
RENDER_ENGINE m_render_engine;
/// mode to render the 3d shape models material
MATERIAL_MODE m_material_mode;
// Pcb board position
/// center board actual position in board units
wxPoint m_boardPos;
/// board actual size in board units
wxSize m_boardSize;
/// 3d center position of the pcb board in 3d units
SFVEC3F m_boardCenter;
// Pcb board bounding boxes
/// 3d bouding box of the pcb board in 3d units
CBBOX m_boardBoudingBox;
/// It contains polygon contours for each layer
MAP_POLY m_layers_poly;
/// It contains polygon contours for holes of each layer (outer holes)
MAP_POLY m_layers_outer_holes_poly;
/// It contains polygon contours for holes of each layer (inner holes)
MAP_POLY m_layers_inner_holes_poly;
/// It contains polygon contours for (just) non plated through holes (outer cylinder)
SHAPE_POLY_SET m_through_outer_holes_poly_NPTH;
/// It contains polygon contours for through holes (outer cylinder)
SHAPE_POLY_SET m_through_outer_holes_poly;
/// It contains polygon contours for through holes (inner cylinder)
SHAPE_POLY_SET m_through_inner_holes_poly;
/// It contains polygon contours for through holes vias (outer cylinder)
SHAPE_POLY_SET m_through_outer_holes_vias_poly;
/// It contains polygon contours for through holes vias (inner cylinder)
SHAPE_POLY_SET m_through_inner_holes_vias_poly;
/// PCB board outline polygon
SHAPE_POLY_SET m_board_poly;
// 2D element containers
/// It contains the 2d elements of each layer
MAP_CONTAINER_2D m_layers_container2D;
/// It contains the holes per each layer
MAP_CONTAINER_2D m_layers_holes2D;
/// It contains the list of throughHoles of the board,
/// the radius of the hole is inflated with the copper tickness
CBVHCONTAINER2D m_through_holes_outer;
/// It contains the list of throughHoles of the board,
/// the radius is the inner hole
CBVHCONTAINER2D m_through_holes_inner;
/// It contains the list of throughHoles vias of the board,
/// the radius of the hole is inflated with the copper tickness
CBVHCONTAINER2D m_through_holes_vias_outer;
/// It contains the list of throughHoles vias of the board,
/// the radius of the hole
CBVHCONTAINER2D m_through_holes_vias_inner;
// Layers information
/// Number of copper layers actually used by the board
unsigned int m_copperLayersCount;
/// Normalization scale to convert board internal units to 3D units to
/// normalize 3D units between -1.0 and +1.0
double m_biuTo3Dunits;
/// Top (End) Z position of each layer (normalized)
float m_layerZcoordTop[PCB_LAYER_ID_COUNT];
/// Bottom (Start) Z position of each layer (normalized)
float m_layerZcoordBottom[PCB_LAYER_ID_COUNT];
/// Copper thickness (normalized)
float m_copperThickness3DU;
/// Epoxy thickness (normalized)
float m_epoxyThickness3DU;
/// Non copper layers thickness
float m_nonCopperLayerThickness3DU;
// Cameras
/// Holds a pointer to current camera in use.
CCAMERA &m_currentCamera;
CTRACK_BALL m_trackBallCamera;
/// min factor used for cicle segment approximation calculation
float m_calc_seg_min_factor3DU;
/// max factor used for cicle segment approximation calculation
float m_calc_seg_max_factor3DU;
// Statistics
/// Number of tracks in the board
unsigned int m_stats_nr_tracks;
/// Track average width
float m_stats_track_med_width;
/// Nr of vias
unsigned int m_stats_nr_vias;
/// Computed medium diameter of the via holes in 3D units
float m_stats_via_med_hole_diameter;
/// number of holes in the board
unsigned int m_stats_nr_holes;
/// Computed medium diameter of the holes in 3D units
float m_stats_hole_med_diameter;
/**
* Trace mask used to enable or disable the trace output of this class.
* The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_EDA_CINFO3D_VISU". See the wxWidgets documentation on wxLogTrace for
* more information.
*/
static const wxChar *m_logTrace;
};
/// This is a dummy visualization configuration
extern CINFO3D_VISU G_null_CINFO3D_VISU;
#endif // CINFO3D_VISU_H
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+243
View File
@@ -0,0 +1,243 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file create_layer_poly.cpp
* @brief This file implements the creation of the pcb board items in the poly
* contours format. It is based on the function found in the files:
* board_items_to_polygon_shape_transform.cpp
* board_items_to_polygon_shape_transform.cpp
*/
#include "cinfo3d_visu.h"
#include <convert_basic_shapes_to_polygon.h>
#include <class_edge_mod.h>
#include <class_module.h>
// This is the same function as in board_items_to_polygon_shape_transform.cpp
// but it adds the rect/trapezoid shapes with a different winding
void CINFO3D_VISU::buildPadShapePolygon( const D_PAD* aPad,
SHAPE_POLY_SET& aCornerBuffer,
wxSize aInflateValue,
int aSegmentsPerCircle,
double aCorrectionFactor ) const
{
wxPoint corners[4];
wxPoint PadShapePos = aPad->ShapePos(); /* Note: for pad having a shape offset,
* the pad position is NOT the shape position */
switch( aPad->GetShape() )
{
case PAD_SHAPE_CIRCLE:
case PAD_SHAPE_OVAL:
case PAD_SHAPE_ROUNDRECT:
{
// We are using TransformShapeWithClearanceToPolygon to build the shape.
// Currently, this method uses only the same inflate value for X and Y dirs.
// so because here this is not the case, we use a inflated dummy pad to build
// the polygonal shape
// TODO: remove this dummy pad when TransformShapeWithClearanceToPolygon will use
// a wxSize to inflate the pad size
D_PAD dummy( *aPad );
wxSize new_size = aPad->GetSize() + aInflateValue + aInflateValue;
dummy.SetSize( new_size );
dummy.TransformShapeWithClearanceToPolygon( aCornerBuffer, 0,
aSegmentsPerCircle, aCorrectionFactor );
}
break;
case PAD_SHAPE_TRAPEZOID:
case PAD_SHAPE_RECT:
{
SHAPE_LINE_CHAIN aLineChain;
aPad->BuildPadPolygon( corners, aInflateValue, aPad->GetOrientation() );
for( int ii = 0; ii < 4; ++ii )
{
corners[3-ii] += PadShapePos; // Shift origin to position
aLineChain.Append( corners[3-ii].x, corners[3-ii].y );
}
aLineChain.SetClosed( true );
aCornerBuffer.AddOutline( aLineChain );
}
break;
case PAD_SHAPE_CUSTOM:
{
SHAPE_POLY_SET polyList; // Will contain the pad outlines in board coordinates
polyList.Append( aPad->GetCustomShapeAsPolygon() );
aPad->CustomShapeAsPolygonToBoardPosition( &polyList, aPad->ShapePos(), aPad->GetOrientation() );
aCornerBuffer.Append( polyList );
}
break;
}
}
void CINFO3D_VISU::buildPadShapeThickOutlineAsPolygon( const D_PAD* aPad,
SHAPE_POLY_SET& aCornerBuffer,
int aWidth ) const
{
if( aPad->GetShape() == PAD_SHAPE_CIRCLE ) // Draw a ring
{
unsigned int nr_sides_per_circle = GetNrSegmentsCircle( ( aPad->GetSize().x / 2 +
aWidth / 2 ) * 2 );
TransformRingToPolygon( aCornerBuffer, aPad->ShapePos(),
aPad->GetSize().x / 2, nr_sides_per_circle, aWidth );
return;
}
// For other shapes, draw polygon outlines
SHAPE_POLY_SET corners;
unsigned int nr_sides_per_circle = GetNrSegmentsCircle( glm::min( aPad->GetSize().x,
aPad->GetSize().y) );
buildPadShapePolygon( aPad, corners, wxSize( 0, 0 ),
nr_sides_per_circle,
GetCircleCorrectionFactor( nr_sides_per_circle ) );
// Add outlines as thick segments in polygon buffer
const SHAPE_LINE_CHAIN& path = corners.COutline( 0 );
for( int ii = 0; ii < path.PointCount(); ++ii )
{
const VECTOR2I& a = path.CPoint( ii );
const VECTOR2I& b = path.CPoint( ii + 1 );
TransformRoundedEndsSegmentToPolygon( aCornerBuffer,
wxPoint( a.x, a.y ),
wxPoint( b.x, b.y ),
nr_sides_per_circle,
aWidth );
}
}
// Based on the same function name in board_items_to_polyshape_transform.cpp
// It was implemented here to allow dynamic segments count per pad shape
void CINFO3D_VISU::transformPadsShapesWithClearanceToPolygon( const DLIST<D_PAD>& aPads, PCB_LAYER_ID aLayer,
SHAPE_POLY_SET& aCornerBuffer,
int aInflateValue,
bool aSkipNPTHPadsWihNoCopper ) const
{
const D_PAD* pad = aPads;
wxSize margin;
for( ; pad != NULL; pad = pad->Next() )
{
if( !pad->IsOnLayer(aLayer) )
continue;
// NPTH pads are not drawn on layers if the shape size and pos is the same
// as their hole:
if( aSkipNPTHPadsWihNoCopper && (pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED) )
{
if( (pad->GetDrillSize() == pad->GetSize()) &&
(pad->GetOffset() == wxPoint( 0, 0 )) )
{
switch( pad->GetShape() )
{
case PAD_SHAPE_CIRCLE:
if( pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
continue;
break;
case PAD_SHAPE_OVAL:
if( pad->GetDrillShape() != PAD_DRILL_SHAPE_CIRCLE )
continue;
break;
default:
break;
}
}
}
switch( aLayer )
{
case F_Mask:
case B_Mask:
margin.x = margin.y = pad->GetSolderMaskMargin() + aInflateValue;
break;
case F_Paste:
case B_Paste:
margin = pad->GetSolderPasteMargin();
margin.x += aInflateValue;
margin.y += aInflateValue;
break;
default:
margin.x = margin.y = aInflateValue;
break;
}
unsigned int aCircleToSegmentsCount = GetNrSegmentsCircle( pad->GetSize().x );
double aCorrectionFactor = GetCircleCorrectionFactor( aCircleToSegmentsCount );
buildPadShapePolygon( pad, aCornerBuffer, margin,
aCircleToSegmentsCount, aCorrectionFactor );
}
}
void CINFO3D_VISU::transformGraphicModuleEdgeToPolygonSet( const MODULE *aModule,
PCB_LAYER_ID aLayer,
SHAPE_POLY_SET& aCornerBuffer ) const
{
for( const EDA_ITEM* item = aModule->GraphicalItemsList();
item != NULL;
item = item->Next() )
{
switch( item->Type() )
{
case PCB_MODULE_EDGE_T:
{
EDGE_MODULE*outline = (EDGE_MODULE*) item;
if( outline->GetLayer() != aLayer )
break;
unsigned int aCircleToSegmentsCount =
GetNrSegmentsCircle( outline->GetBoundingBox().GetSizeMax() );
double aCorrectionFactor = GetCircleCorrectionFactor( aCircleToSegmentsCount );
outline->TransformShapeWithClearanceToPolygon( aCornerBuffer,
0,
aCircleToSegmentsCount,
aCorrectionFactor );
}
break;
default:
break;
}
}
}
File diff suppressed because it is too large Load Diff
+164 -208
View File
@@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -22,73 +22,61 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file eda_3d_canvas.h
* @brief
*/
#ifndef EDA_3D_CANVAS_H
#define EDA_3D_CANVAS_H
#include <atomic>
#include "board_adapter.h"
#include "3d_rendering/raytracing/accelerators/accelerator_3d.h"
#include "3d_rendering/render_3d_base.h"
#include "cinfo3d_visu.h"
#include "3d_rendering/c3d_render_base.h"
#include "3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.h"
#include "3d_rendering/3d_render_raytracing/c3d_render_raytracing.h"
#include "3d_cache/3d_cache.h"
#include <gal/hidpi_gl_3D_canvas.h>
#include <gal/hidpi_gl_canvas.h>
#include <wx/clipbrd.h>
#include <wx/dataobj.h>
#include <wx/image.h>
#include <wx/wupdlock.h>
#include <wx/timer.h>
#include <wx/statusbr.h>
#include <pcb_base_frame.h>
class WX_INFOBAR;
class wxStatusBar;
class BOARD;
class RENDER_3D_RAYTRACE_GL;
class RENDER_3D_OPENGL;
#define EDA_3D_CANVAS_ID wxID_HIGHEST + 1321
/**
* Implement a canvas based on a wxGLCanvas
*/
class EDA_3D_CANVAS : public HIDPI_GL_3D_CANVAS
class EDA_3D_CANVAS : public HIDPI_GL_CANVAS
{
public:
public:
/**
* Create a new 3D Canvas with an attribute list.
*
* @param aParent the parent creator of this canvas.
* @param aGLAttribs openGL attributes created by #OGL_ATT_LIST::GetAttributesList.
* @param aBoard The board.
* @param aSettings the settings options to be used by this canvas.
* @brief EDA_3D_CANVAS - Creates a new 3D Canvas with a attribute list
* @param aParent: the parent creator of this canvas
* @param aAttribList: a list of openGL options created by GetOpenGL_AttributesList
* @param aBoard: The board
* @param aSettings: the settings options to be used by this canvas
*/
EDA_3D_CANVAS( wxWindow* aParent, const wxGLAttributes& aGLAttribs, BOARD_ADAPTER& aSettings,
CAMERA& aCamera, S3D_CACHE* a3DCachePointer );
EDA_3D_CANVAS( wxWindow *aParent,
const int *aAttribList = 0,
BOARD *aBoard = NULL,
CINFO3D_VISU &aSettings = G_null_CINFO3D_VISU,
S3D_CACHE *a3DCachePointer = NULL );
~EDA_3D_CANVAS();
/**
* Set a dispatcher that processes events and forwards them to tools.
*
* #DRAW_PANEL_GAL does not take over the ownership. Passing NULL disconnects all event
* handlers from the DRAW_PANEL_GAL and parent frame.
*
* @param aEventDispatcher is the object that will be used for dispatching events.
*/
void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher );
void SetStatusBar( wxStatusBar *aStatusBar ) { m_parentStatusBar = aStatusBar; }
void SetStatusBar( wxStatusBar* aStatusBar )
{
m_parentStatusBar = aStatusBar;
}
void SetInfoBar( WX_INFOBAR* aInfoBar )
{
m_parentInfoBar = aInfoBar;
}
void ReloadRequest( BOARD* aBoard = nullptr, S3D_CACHE* aCachePointer = nullptr );
void ReloadRequest( BOARD *aBoard = NULL, S3D_CACHE *aCachePointer = NULL );
/**
* Query if there is a pending reload request.
*
* @return true if it wants to reload, false if there is no reload pending.
* @brief IsReloadRequestPending - Query if there is a pending reload request
* @return true if it wants to reload, false if there is no reload pending
*/
bool IsReloadRequestPending() const
{
@@ -99,241 +87,209 @@ public:
}
/**
* @return the current render ( a RENDER_3D_RAYTRACE_GL* or a RENDER_3D_OPENGL* render )
*/
RENDER_3D_BASE* GetCurrentRender() const { return m_3d_render; }
/**
* Request to render the current view in Raytracing mode.
* @brief RenderRaytracingRequest - Request to render the current view in Raytracing mode
*/
void RenderRaytracingRequest();
/**
* Request a screenshot and output it to the \a aDstImage.
*
* @param aDstImage - Screenshot destination image.
* Request a screenshot and output it to the aDstImage
* @param aDstImage - Screenshot destination image
*/
void GetScreenshot( wxImage& aDstImage );
void GetScreenshot( wxImage &aDstImage );
/**
* Select a specific 3D view or operation.
*
* @param aRequestedView the view to move to.
* @return true if the view request was handled, false if no command found for this view.
* @brief SetView3D - Helper function to call view commands
* @param aKeycode: ascii key commands
* @return true if the key code was handled,
* false if no command found for this code.
*/
bool SetView3D( VIEW3D_TYPE aRequestedView );
bool SetView3D( int aKeycode );
/**
* Enable or disable camera animation when switching to a pre-defined view.
*/
void SetAnimationEnabled( bool aEnable ) { m_animation_enabled = aEnable; }
bool GetAnimationEnabled() const { return m_animation_enabled; }
/**
* Set the camera animation moving speed multiplier option.
*
* @param aMultiplier one of the possible integer options: [1,2,3,4,5].
*/
void SetMovingSpeedMultiplier( int aMultiplier ) { m_moving_speed_multiplier = aMultiplier; }
int GetMovingSpeedMultiplier() const { return m_moving_speed_multiplier; }
int GetProjectionMode() const { return (int) m_camera.GetProjection(); };
void SetProjectionMode( int aMode ) { m_camera.SetProjection( (PROJECTION_TYPE) aMode ); }
/**
* Notify that the render engine was changed.
* @brief RenderEngineChanged - Notify that the render engine was changed
*/
void RenderEngineChanged();
/**
* Update the status bar with the position information.
* @brief DisplayStatus - Update the status bar with the position information
*/
void DisplayStatus();
/**
* Schedule a refresh update of the canvas.
*
* @param aRedrawImmediately true will request a redraw, false will schedule a redraw
* after a short timeout.
* @brief Request_refresh - Schedule a refresh update of the canvas
* @param aRedrawImmediately - true will request a redraw, false will
* schedule a redraw, after a short timeout.
*/
void Request_refresh( bool aRedrawImmediately = true );
/**
* Used to forward events to the canvas from popups, etc.
*/
void OnEvent( wxEvent& aEvent );
void OnKeyEvent( wxKeyEvent& event );
bool SupportsRayTracing() const { return m_opengl_supports_raytracing; }
bool IsOpenGLInitialized() const { return m_is_opengl_initialized; }
/**
* Get information used to display 3D board.
* Return a structure containing currently used hotkey mapping.
*/
const BOARD_ADAPTER& GetBoardAdapter() const { return m_boardAdapter; }
EDA_HOTKEY_CONFIG* GetHotkeyConfig() const;
/**
* Get a value indicating whether to render the pivot.
private:
/** Called by a wxPaintEvent event
*/
bool GetRenderPivot() { return m_render_pivot; }
/**
* Set aValue indicating whether to render the pivot.
*
* @param aValue true will cause the pivot to be rendered on the next redraw.
*/
void SetRenderPivot( bool aValue ) { m_render_pivot = aValue; }
/**
* Get a value indicating whether to render the 3dmouse pivot.
*/
bool GetRender3dmousePivot()
{
return m_render3dmousePivot;
}
/**
* Set aValue indicating whether to render the 3dmouse pivot.
*
* @param aValue true will cause the pivot to be rendered on the next redraw.
*/
void SetRender3dmousePivot( bool aValue )
{
m_render3dmousePivot = aValue;
}
/**
* Set the position of the the 3dmouse pivot.
*
* @param aPos is the position of the 3dmouse rotation pivot
*/
void Set3dmousePivotPos( const SFVEC3F& aPos )
{
m_3dmousePivotPos = aPos;
}
void OnPaint( wxPaintEvent& aEvent );
/**
* The actual function to repaint the canvas.
*
* It is usually called by OnPaint() but because it does not use a wxPaintDC it can be
* called outside a wxPaintEvent
* It is usually called by OnPaint() but because it does not use a wxPaintDC
* it can be called outside a wxPaintEvent
*/
void DoRePaint();
void OnCloseWindow( wxCloseEvent& event );
private:
// The wxPaintEvent event. mainly calls DoRePaint()
void OnPaint( wxPaintEvent& aEvent );
void OnEraseBackground( wxEraseEvent& event );
void OnEraseBackground( wxEraseEvent &event );
void OnRefreshRequest( wxEvent& aEvent );
void OnMouseWheel( wxMouseEvent& event );
void OnMouseWheel( wxMouseEvent &event );
#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
void OnMagnify( wxMouseEvent& event );
#endif
void OnMouseMove( wxMouseEvent &event );
void OnLeftDown( wxMouseEvent &event );
void OnLeftUp( wxMouseEvent &event );
void OnMiddleUp( wxMouseEvent &event );
void OnMiddleDown( wxMouseEvent &event );
void OnRightClick( wxMouseEvent &event );
void OnPopUpMenu( wxCommandEvent &event );
void OnCharHook( wxKeyEvent& event );
void OnMagnify( wxMouseEvent& event );
void OnMouseMove( wxMouseEvent& event );
void OnLeftDown( wxMouseEvent& event );
void OnLeftUp( wxMouseEvent& event );
void OnMiddleUp( wxMouseEvent& event );
void OnMiddleDown( wxMouseEvent& event );
void OnTimerTimeout_Editing( wxTimerEvent& event );
void OnResize( wxSizeEvent& event );
void OnTimerTimeout_Redraw( wxTimerEvent& event );
void OnZoomGesture( wxZoomGestureEvent& event );
void OnPanGesture( wxPanGestureEvent& event );
void OnRotateGesture( wxRotateGestureEvent& event );
/**
* @brief OnCloseWindow - called when the frame is closed
* @param event
*/
void OnCloseWindow( wxCloseEvent &event );
void OnResize( wxSizeEvent &event );
void OnTimerTimeout_Redraw( wxTimerEvent& event );
DECLARE_EVENT_TABLE()
private:
/**
*Stop the editing time so it will not timeout.
* @brief stop_editingTimeOut_Timer - stop the editing time, so it will not timeout
*/
void stop_editingTimeOut_Timer();
/**
* Reset the editing timer.
* @brief restart_editingTimeOut_Timer - reset the editing timer
*/
void restart_editingTimeOut_Timer();
/**
* Start a camera movement.
*
* @param aMovingSpeed the time speed.
* @param aRenderPivot if it should display pivot cursor while move.
*/
void request_start_moving_camera( float aMovingSpeed = 2.0f, bool aRenderPivot = true );
/**
* This function hits a ray to the board and start a movement.
* @brief request_start_moving_camera - start a camera movement
* @param aMovingSpeed: the time speed
* @param aRenderPivot: if it should display pivot cursor while move
*/
void request_start_moving_camera( float aMovingSpeed = 2.0f,
bool aRenderPivot = true );
/**
* @brief move_pivot_based_on_cur_mouse_position -
* This function hits a ray to the board and start a moviment
*/
void move_pivot_based_on_cur_mouse_position();
/**
* Render the pivot cursor.
*
* @param t time between 0.0 and 1.0.
* @param aScale scale to apply on the cursor.
* @brief render_pivot - render the pivot cursor
* @param t: time between 0.0 and 1.0
* @param aScale: scale to apply on the cursor
*/
void render_pivot( float t, float aScale );
/**
* Render the 3dmouse pivot cursor.
*
* @param aScale scale to apply on the cursor.
*/
void render3dmousePivot( float aScale );
/**
* @return true if OpenGL initialization succeeded.
* @brief initializeOpenGL
* @return if OpenGL initialization succeed
*/
bool initializeOpenGL();
/**
* Free created targets and openGL context.
* @brief releaseOpenGL - free created targets and openGL context
*/
void releaseOpenGL();
RAY getRayAtCurrentMousePosition();
private:
private:
TOOL_DISPATCHER* m_eventDispatcher;
wxStatusBar* m_parentStatusBar; // Parent statusbar to report progress
WX_INFOBAR* m_parentInfoBar;
/// current OpenGL context
wxGLContext *m_glRC;
wxGLContext* m_glRC; // Current OpenGL context
bool m_is_opengl_initialized;
bool m_is_opengl_version_supported;
/// Parent statusbar to report progress
wxStatusBar *m_parentStatusBar;
wxTimer m_editing_timeout_timer; // Expires after some time signaling that
// the mouse / keyboard movements are over
wxTimer m_redraw_trigger_timer; // Used to schedule a redraw event
std::atomic_flag m_is_currently_painting; // Avoid drawing twice at the same time
/// Time timeout will expires after some time sinalizing that the mouse /
/// keyboard movements are over.
wxTimer m_editing_timeout_timer;
bool m_render_pivot; // Render the pivot while camera moving
float m_camera_moving_speed; // 1.0f will be 1:1
int64_t m_strtime_camera_movement; // Ticktime of camera movement start
bool m_animation_enabled; // Camera animation enabled
int m_moving_speed_multiplier; // Camera animation speed multiplier option
/// This timer will be used to schedule a redraw event
wxTimer m_redraw_trigger_timer;
BOARD_ADAPTER& m_boardAdapter; // Pre-computed 3D info and settings
RENDER_3D_BASE* m_3d_render;
RENDER_3D_RAYTRACE_GL* m_3d_render_raytracing;
RENDER_3D_OPENGL* m_3d_render_opengl;
/// true if mouse activity is on progress
bool m_mouse_is_moving;
bool m_opengl_supports_raytracing;
bool m_render_raytracing_was_requested;
/// true if there was some type of activity, it will be used to render in
/// preview mode
bool m_mouse_was_moved;
ACCELERATOR_3D* m_accelerator3DShapes; // used for mouse over searching
/// true if camera animation is ongoing
bool m_camera_is_moving;
BOARD_ITEM* m_currentRollOverItem;
/// activated the render of pivot while camera moving
bool m_render_pivot;
bool m_render3dmousePivot = false; // Render the 3dmouse pivot
SFVEC3F m_3dmousePivotPos; // The position of the 3dmouse pivot
/// 1.0f will be 1:1
float m_camera_moving_speed;
/// Used to track gesture events.
double m_gestureLastZoomFactor = 1.0;
double m_gestureLastAngle = 0.0;
/// Stores the ticktime when the camera star its movement
unsigned m_strtime_camera_movement;
/// Stores all pre-computed 3D information and visualization settings to render the board
CINFO3D_VISU &m_settings;
/// The current render in used for this canvas
C3D_RENDER_BASE *m_3d_render;
/// Raytracing render class
C3D_RENDER_RAYTRACING *m_3d_render_raytracing;
/// OpenGL legacy render class
C3D_RENDER_OGL_LEGACY *m_3d_render_ogl_legacy;
/// Flag to store if opengl was initialized already
bool m_is_opengl_initialized;
/// Step factor to used with cursor on relation to the current zoom
static const float m_delta_move_step_factor;
/// Flags that the user requested the current view to be render with raytracing
bool m_render_raytracing_was_requested;
bool m_opengl_supports_raytracing;
/**
* Trace mask used to enable or disable the trace output of this class.
@@ -341,7 +297,7 @@ private:
* "KI_TRACE_EDA_3D_CANVAS". See the wxWidgets documentation on wxLogTrace for
* more information.
*/
static const wxChar* m_logTrace;
static const wxChar *m_logTrace;
};
+21 -60
View File
@@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -35,26 +35,26 @@
static void pivot_render_triangles( float t )
{
wxASSERT( t >= 0.0f );
SFVEC3F vertexPointer[12];
const float u = 1.0f / 6.0f;
vertexPointer[0] = SFVEC3F( ( -3.0f + t ) * u, -2.0f * u, 0.0f );
vertexPointer[1] = SFVEC3F( ( -3.0f + t ) * u, 2.0f * u, 0.0f );
vertexPointer[2] = SFVEC3F( ( -1.0f + t ) * u, 0.0f * u, 0.0f );
vertexPointer[0] = SFVEC3F( (-3.0f + t) * u, -2.0f * u, 0.0f );
vertexPointer[1] = SFVEC3F( (-3.0f + t) * u, 2.0f * u, 0.0f );
vertexPointer[2] = SFVEC3F( (-1.0f + t) * u, 0.0f * u, 0.0f );
vertexPointer[3] = SFVEC3F( -2.0f * u, ( -3.0f + t ) * u, 0.0f );
vertexPointer[4] = SFVEC3F( 2.0f * u, ( -3.0f + t ) * u, 0.0f );
vertexPointer[5] = SFVEC3F( 0.0f * u, ( -1.0f + t ) * u, 0.0f );
vertexPointer[3] = SFVEC3F( -2.0f * u, (-3.0f + t) * u, 0.0f );
vertexPointer[4] = SFVEC3F( 2.0f * u, (-3.0f + t) * u, 0.0f );
vertexPointer[5] = SFVEC3F( 0.0f * u, (-1.0f + t) * u, 0.0f );
vertexPointer[6] = SFVEC3F( ( 3.0f - t ) * u, -2.0f * u, 0.0f );
vertexPointer[7] = SFVEC3F( ( 3.0f - t ) * u, 2.0f * u, 0.0f );
vertexPointer[8] = SFVEC3F( ( 1.0f - t ) * u, 0.0f * u, 0.0f );
vertexPointer[6] = SFVEC3F( (3.0f - t) * u, -2.0f * u, 0.0f );
vertexPointer[7] = SFVEC3F( (3.0f - t) * u, 2.0f * u, 0.0f );
vertexPointer[8] = SFVEC3F( (1.0f - t) * u, 0.0f * u, 0.0f );
vertexPointer[9] = SFVEC3F( 2.0f * u, ( 3.0f - t ) * u, 0.0f );
vertexPointer[10] = SFVEC3F( -2.0f * u, ( 3.0f - t ) * u, 0.0f );
vertexPointer[11] = SFVEC3F( 0.0f * u, ( 1.0f - t ) * u, 0.0f );
vertexPointer[9] = SFVEC3F( 2.0f * u, (3.0f - t) * u, 0.0f );
vertexPointer[10] = SFVEC3F( -2.0f * u, (3.0f - t) * u, 0.0f );
vertexPointer[11] = SFVEC3F( 0.0f * u, (1.0f - t) * u, 0.0f );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );
@@ -73,7 +73,7 @@ static void pivot_render_triangles( float t )
}
void EDA_3D_CANVAS::render_pivot( float t, float aScale )
void EDA_3D_CANVAS::render_pivot( float t , float aScale )
{
wxASSERT( aScale >= 0.0f );
wxASSERT( t >= 0.0f );
@@ -81,27 +81,29 @@ void EDA_3D_CANVAS::render_pivot( float t, float aScale )
if( t > 1.0f )
t = 1.0f;
const SFVEC3F &lookAtPos = m_camera.GetLookAtPos_T1();
const SFVEC3F &lookAtPos = m_settings.CameraGet().GetLookAtPos_T1();
glDisable( GL_LIGHTING );
glDisable( GL_DEPTH_TEST );
glDisable( GL_CULL_FACE );
// Set projection and modelview matrixes
// /////////////////////////////////////////////////////////////////////////
glMatrixMode( GL_PROJECTION );
glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
glLoadMatrixf( glm::value_ptr( m_settings.CameraGet().GetProjectionMatrix() ) );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
glLoadMatrixf( glm::value_ptr( m_settings.CameraGet().GetViewMatrix() ) );
glEnable( GL_COLOR_MATERIAL );
glColor4f( 0.0f, 1.0f, 0.0f, 0.75f - t * 0.75f );
// Translate to the look at position
glTranslatef( lookAtPos.x, lookAtPos.y, lookAtPos.z );
glScalef( aScale, aScale, aScale );
pivot_render_triangles( t * 0.5f );
t = t * 0.80f;
@@ -118,44 +120,3 @@ void EDA_3D_CANVAS::render_pivot( float t, float aScale )
pivot_render_triangles( t * 0.5f );
glPopMatrix();
}
void EDA_3D_CANVAS::render3dmousePivot( float aScale )
{
wxASSERT( aScale >= 0.0f );
glDisable( GL_LIGHTING );
glDisable( GL_DEPTH_TEST );
glDisable( GL_CULL_FACE );
// Set projection and modelview matrixes
glMatrixMode( GL_PROJECTION );
glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
glEnable( GL_COLOR_MATERIAL );
glColor4f( 0.0f, 0.667f, 0.902f, 0.75f );
// Translate to the look at position
glTranslatef( m_3dmousePivotPos.x, m_3dmousePivotPos.y, m_3dmousePivotPos.z );
glPointSize( 16.0f );
glEnable( GL_POINT_SMOOTH );
glHint( GL_POINT_SMOOTH_HINT, GL_NICEST );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glScalef( aScale, aScale, aScale );
// Draw a point at the look at position.
glBegin( GL_POINTS );
glVertex3f( 0, 0, 0 );
glEnd();
glDisable( GL_BLEND );
glDisable( GL_POINT_SMOOTH );
}
@@ -0,0 +1,68 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file status_text_reporter.h
* @brief
*/
#ifndef STATUS_TEXT_REPORTER_H_
#define STATUS_TEXT_REPORTER_H_
#include <reporter.h>
/**
* Class STATUS_TEXT_REPORTER
* is a wrapper for reporting to a wxString in a wxFrame status text.
*/
class STATUS_TEXT_REPORTER : public REPORTER
{
private:
wxStatusBar *m_parentStatusBar;
int m_position;
bool m_hasMessage;
public:
STATUS_TEXT_REPORTER( wxStatusBar* aParentStatusBar, int aPosition = 0 ) :
REPORTER(),
m_parentStatusBar( aParentStatusBar ), m_position( aPosition )
{
m_hasMessage = false;
}
REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override
{
if( !aText.IsEmpty() )
m_hasMessage = true;
if( m_parentStatusBar )
m_parentStatusBar->SetStatusText( aText, m_position );
return *this;
}
bool HasMessage() const override { return m_hasMessage; }
};
#endif // STATUS_TEXT_REPORTER_H_
+97
View File
@@ -0,0 +1,97 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file 3d_enums.h
* @brief declared enumerations and flags
*/
#ifndef _3D_ENUMS_H_
#define _3D_ENUMS_H_
/// Flags used in rendering options
enum DISPLAY3D_FLG {
FL_AXIS=0, FL_ZONE,
FL_ADHESIVE, FL_SILKSCREEN, FL_SOLDERMASK, FL_SOLDERPASTE,
FL_COMMENTS, FL_ECO,
FL_MODULE_ATTRIBUTES_NORMAL,
FL_MODULE_ATTRIBUTES_NORMAL_INSERT,
FL_MODULE_ATTRIBUTES_VIRTUAL,
FL_SHOW_BOARD_BODY,
FL_MOUSEWHEEL_PANNING,
FL_USE_REALISTIC_MODE,
// OpenGL options
FL_RENDER_OPENGL_SHOW_MODEL_BBOX,
FL_RENDER_OPENGL_COPPER_THICKNESS,
// Raytracing options
FL_RENDER_RAYTRACING_SHADOWS,
FL_RENDER_RAYTRACING_BACKFLOOR,
FL_RENDER_RAYTRACING_REFRACTIONS,
FL_RENDER_RAYTRACING_REFLECTIONS,
FL_RENDER_RAYTRACING_POST_PROCESSING,
FL_RENDER_RAYTRACING_ANTI_ALIASING,
FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES,
FL_LAST
};
/// Camera types
enum CAMERA_TYPE
{
CAMERA_TRACKBALL
};
/// Grid types
enum GRID3D_TYPE
{
GRID3D_NONE,
GRID3D_1MM,
GRID3D_2P5MM,
GRID3D_5MM,
GRID3D_10MM
};
/// Render engine mode
enum RENDER_ENGINE
{
RENDER_ENGINE_OPENGL_LEGACY,
RENDER_ENGINE_RAYTRACING,
};
/// Render 3d model shape materials mode
enum MATERIAL_MODE
{
MATERIAL_MODE_NORMAL, ///< Use all material properties from model file
MATERIAL_MODE_DIFFUSE_ONLY, ///< Use only diffuse material properties
MATERIAL_MODE_CAD_MODE ///< Use a gray shading based on diffuse material
};
#endif // _3D_ENUMS_H_
+1 -1
View File
@@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
+3 -3
View File
@@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -30,9 +30,9 @@
#ifndef _3D_FASTMATH_H
#define _3D_FASTMATH_H
#include <string.h>
#include <stdint.h>
#include <cmath>
#include <cstdint>
#include <cstring>
// Define this flag to use fast math optimizations
+1 -1
View File
@@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
+39 -30
View File
@@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -33,43 +33,44 @@
#include <plugins/3dapi/xv3d_types.h>
#include "3d_fastmath.h"
// https://en.wikipedia.org/wiki/Spherical_coordinate_system
/**
* https://en.wikipedia.org/wiki/Spherical_coordinate_system
*
* @brief SphericalToCartesian
* @param aInclination θ [0, π]
* @param aAzimuth φ [0, 2π]
* @return Cartesian coordinates
* @return Cartesian cordinates
*/
inline SFVEC3F SphericalToCartesian( float aInclination, float aAzimuth )
{
float sinInc = glm::sin( aInclination );
return SFVEC3F( sinInc * glm::cos( aAzimuth ), sinInc * glm::sin( aAzimuth ),
return SFVEC3F( sinInc * glm::cos( aAzimuth ),
sinInc * glm::sin( aAzimuth ),
glm::cos( aInclination ) );
}
/**
* @todo This is not correct because it is not a gaussian random.
*/
inline SFVEC3F UniformRandomHemisphereDirection()
// https://pathtracing.wordpress.com/2011/03/03/cosine-weighted-hemisphere/
// !TODO: this is not correct because it is not a gaussian random
inline SFVEC3F UniformRandomHemisphereDirection( )
{
// It was experienced that this function is slow! do not use it :/
// SFVEC3F b( (rand()/(float)RAND_MAX) - 0.5f,
// (rand()/(float)RAND_MAX) - 0.5f,
// (rand()/(float)RAND_MAX) - 0.5f );
SFVEC3F b( Fast_RandFloat() * 0.5f, Fast_RandFloat() * 0.5f, Fast_RandFloat() * 0.5f );
SFVEC3F b( Fast_RandFloat() * 0.5f,
Fast_RandFloat() * 0.5f,
Fast_RandFloat() * 0.5f );
return b;
}
// https://pathtracing.wordpress.com/2011/03/03/cosine-weighted-hemisphere/
inline SFVEC3F CosWeightedRandomHemisphereDirection( const SFVEC3F& n )
inline SFVEC3F CosWeightedRandomHemisphereDirection( const SFVEC3F &n )
{
const float Xi1 = (float) rand() / (float) RAND_MAX;
const float Xi2 = (float) rand() / (float) RAND_MAX;
const float Xi1 = (float)rand() / (float)RAND_MAX;
const float Xi2 = (float)rand() / (float)RAND_MAX;
const float theta = acos( sqrt( 1.0f - Xi1 ) );
const float phi = 2.0f * glm::pi<float>() * Xi2;
@@ -98,19 +99,21 @@ inline SFVEC3F CosWeightedRandomHemisphereDirection( const SFVEC3F& n )
/**
* @brief Refract
* Based on:
* https://github.com/mmp/pbrt-v3/blob/master/src/core/reflection.h
* See also:
* http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_3_Refractions_and_Beers_Law.shtml
*
* @param aInVector incoming vector.
* @param aNormal normal in the intersection point.
* @param aRin_over_Rout incoming refraction index / out refraction index.
* @param aOutVector the refracted vector.
* @param aInVector incoming vector
* @param aNormal normal in the intersection point
* @param aRin_over_Rout incoming refraction index / out refraction index
* @param aOutVector the refracted vector
* @return true
*/
inline bool Refract( const SFVEC3F &aInVector, const SFVEC3F &aNormal, float aRin_over_Rout,
SFVEC3F& aOutVector )
inline bool Refract( const SFVEC3F &aInVector,
const SFVEC3F &aNormal,
float aRin_over_Rout,
SFVEC3F &aOutVector )
{
float cosThetaI = -glm::dot( aNormal, aInVector );
float sin2ThetaI = glm::max( 0.0f, 1.0f - cosThetaI * cosThetaI );
@@ -130,7 +133,11 @@ inline bool Refract( const SFVEC3F &aInVector, const SFVEC3F &aNormal, float aRi
}
inline float mapf( float x, float in_min, float in_max, float out_min, float out_max )
inline float mapf( float x,
float in_min,
float in_max,
float out_min,
float out_max)
{
x = glm::clamp( x, in_min, in_max );
@@ -147,15 +154,17 @@ inline float RGBtoGray( const SFVEC3F &aColor )
inline SFVEC3F MaterialDiffuseToColorCAD( const SFVEC3F &aDiffuseColor )
{
// convert to a discret scale of grays
const float luminance = glm::min(
( ( (float) ( (unsigned int) ( 4.0f * RGBtoGray( aDiffuseColor ) ) ) + 0.5f ) / 4.0f )
* 1.0f,
1.0f );
const float luminance = glm::min( (((float)((unsigned int) ( 4.0f *
RGBtoGray( aDiffuseColor ) ) ) + 0.5f) /
4.0f) * 1.0f,
1.0f );
const float maxValue = glm::max( glm::max( glm::max( aDiffuseColor.r, aDiffuseColor.g ),
aDiffuseColor.b ), FLT_EPSILON );
const float maxValue = glm::max( glm::max( glm::max( aDiffuseColor.r,
aDiffuseColor.g),
aDiffuseColor.b ),
FLT_EPSILON );
return ( aDiffuseColor / SFVEC3F( maxValue ) ) * 0.125f + luminance * 0.875f;
return (aDiffuseColor / SFVEC3F(maxValue) ) * 0.125f + luminance* 0.875f;
}
@@ -170,7 +179,7 @@ inline float QuadricEasingInOut( float t )
{
t = t - 1.0f;
return -2.0f * ( t * t ) + 1.0f;
return -2.0f * (t * t) + 1.0f;
}
}
@@ -0,0 +1,471 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file c3d_model_viewer.cpp
* @brief Implements a model viewer canvas. The propose of model viewer is to
* render 3d models that come in the original data from the files without any
* transformations.
*/
#include <iostream>
#include "3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.h"
#include "c3d_model_viewer.h"
#include "../3d_rendering/3d_render_ogl_legacy/ogl_legacy_utils.h"
#include "../3d_cache/3d_cache.h"
#include "common_ogl/ogl_utils.h"
#include <wx/dcclient.h>
#include <base_units.h>
#include <gl_context_mgr.h>
/**
* Scale convertion from 3d model units to pcb units
*/
#define UNITS3D_TO_UNITSPCB (IU_PER_MM)
/**
* Trace mask used to enable or disable the trace output of this class.
* The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_EDA_3D_MODEL_VIEWER". See the wxWidgets documentation on wxLogTrace for
* more information.
*/
const wxChar * C3D_MODEL_VIEWER::m_logTrace = wxT( "KI_TRACE_EDA_3D_MODEL_VIEWER" );
BEGIN_EVENT_TABLE( C3D_MODEL_VIEWER, wxGLCanvas )
EVT_PAINT( C3D_MODEL_VIEWER::OnPaint )
// mouse events
EVT_LEFT_DOWN( C3D_MODEL_VIEWER::OnLeftDown )
EVT_LEFT_UP( C3D_MODEL_VIEWER::OnLeftUp )
EVT_MIDDLE_UP( C3D_MODEL_VIEWER::OnMiddleUp )
EVT_MIDDLE_DOWN(C3D_MODEL_VIEWER::OnMiddleDown)
EVT_RIGHT_DOWN( C3D_MODEL_VIEWER::OnRightClick )
EVT_MOUSEWHEEL( C3D_MODEL_VIEWER::OnMouseWheel )
EVT_MOTION( C3D_MODEL_VIEWER::OnMouseMove )
#ifdef USE_OSX_MAGNIFY_EVENT
EVT_MAGNIFY( C3D_MODEL_VIEWER::OnMagnify )
#endif
// other events
EVT_ERASE_BACKGROUND( C3D_MODEL_VIEWER::OnEraseBackground )
END_EVENT_TABLE()
// This defines the range that all coord will have to be rendered.
// It will use this value to convert to a normalized value between
// -(RANGE_SCALE_3D/2) .. +(RANGE_SCALE_3D/2)
#define RANGE_SCALE_3D 8.0f
C3D_MODEL_VIEWER::C3D_MODEL_VIEWER(wxWindow *aParent,
const int *aAttribList , S3D_CACHE *aCacheManager) :
HIDPI_GL_CANVAS( aParent,
wxID_ANY,
aAttribList,
wxDefaultPosition,
wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE ),
m_trackBallCamera( RANGE_SCALE_3D * 2.0f ),
m_cacheManager(aCacheManager)
{
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::C3D_MODEL_VIEWER" ) );
m_ogl_initialized = false;
m_reload_is_needed = false;
m_ogl_3dmodel = NULL;
m_3d_model = NULL;
m_BiuTo3Dunits = 1.0;
m_glRC = NULL;
}
C3D_MODEL_VIEWER::~C3D_MODEL_VIEWER()
{
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::~C3D_MODEL_VIEWER" ) );
if( m_glRC )
{
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
delete m_ogl_3dmodel;
m_ogl_3dmodel = NULL;
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glRC );
}
}
void C3D_MODEL_VIEWER::Set3DModel( const S3DMODEL &a3DModel )
{
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::Set3DModel with a S3DMODEL" ) );
// Validate a3DModel pointers
wxASSERT( a3DModel.m_Materials != NULL );
wxASSERT( a3DModel.m_Meshes != NULL );
wxASSERT( a3DModel.m_MaterialsSize > 0 );
wxASSERT( a3DModel.m_MeshesSize > 0 );
// Delete the old model
delete m_ogl_3dmodel;
m_ogl_3dmodel = NULL;
m_3d_model = NULL;
if( (a3DModel.m_Materials != NULL) && (a3DModel.m_Meshes != NULL) &&
(a3DModel.m_MaterialsSize > 0) && (a3DModel.m_MeshesSize > 0) )
{
m_3d_model = &a3DModel;
m_reload_is_needed = true;
}
Refresh();
}
void C3D_MODEL_VIEWER::Set3DModel(const wxString &aModelPathName)
{
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::Set3DModel with a wxString" ) );
if( m_cacheManager )
{
const S3DMODEL* model = m_cacheManager->GetModel( aModelPathName );
if( model )
Set3DModel( (const S3DMODEL &)*model );
else
Clear3DModel();
}
}
void C3D_MODEL_VIEWER::Clear3DModel()
{
// Delete the old model
m_reload_is_needed = false;
delete m_ogl_3dmodel;
m_ogl_3dmodel = NULL;
m_3d_model = NULL;
Refresh();
}
void C3D_MODEL_VIEWER::ogl_initialize()
{
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
glEnable( GL_DEPTH_TEST );
//glDepthFunc( GL_LEQUAL );
glEnable( GL_CULL_FACE );
glShadeModel( GL_SMOOTH );
glEnable( GL_LINE_SMOOTH );
glEnable( GL_NORMALIZE );
// Setup light
// https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
// /////////////////////////////////////////////////////////////////////////
const GLfloat ambient[] = { 0.01f, 0.01f, 0.01f, 1.0f };
const GLfloat diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
// defines a directional light that points along the negative z-axis
const GLfloat position[] = { 0.0f, 0.0f, 2.0f * RANGE_SCALE_3D, 0.0f };
const GLfloat lmodel_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
glLightfv( GL_LIGHT0, GL_SPECULAR, specular );
glLightfv( GL_LIGHT0, GL_POSITION, position );
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient );
}
void C3D_MODEL_VIEWER::ogl_set_arrow_material()
{
glEnable( GL_COLOR_MATERIAL );
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
const SFVEC4F specular = SFVEC4F( 0.1f, 0.1f, 0.1f, 1.0f );
glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 96.0f );
}
void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
{
wxPaintDC( this );
event.Skip( false );
// SwapBuffer requires the window to be shown before calling
if( !IsShownOnScreen() )
{
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnPaint !IsShown" ) );
return;
}
// "Makes the OpenGL state that is represented by the OpenGL rendering
// context context current, i.e. it will be used by all subsequent OpenGL calls.
// This function may only be called when the window is shown on screen"
if( m_glRC == NULL )
m_glRC = GL_CONTEXT_MANAGER::Get().CreateCtx( this );
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
// Set the OpenGL viewport according to the client size of this canvas.
// This is done here rather than in a wxSizeEvent handler because our
// OpenGL rendering context (and thus viewport setting) is used with
// multiple canvases: If we updated the viewport in the wxSizeEvent
// handler, changing the size of one canvas causes a viewport setting that
// is wrong when next another canvas is repainted.
wxSize clientSize = GetClientSize();
if( !m_ogl_initialized )
{
m_ogl_initialized = true;
ogl_initialize();
}
if( m_reload_is_needed )
{
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnPaint m_reload_is_needed" ) );
m_reload_is_needed = false;
m_ogl_3dmodel = new C_OGL_3DMODEL( *m_3d_model, MATERIAL_MODE_NORMAL );
// It convert a model as it was a board, so get the max size dimension of the board
// and compute the conversion scale
m_BiuTo3Dunits = (double)RANGE_SCALE_3D /
( (double)m_ogl_3dmodel->GetBBox().GetMaxDimension() *
UNITS3D_TO_UNITSPCB );
}
glViewport( 0, 0, clientSize.x, clientSize.y );
m_trackBallCamera.SetCurWindowSize( clientSize );
// clear color and depth buffers
// /////////////////////////////////////////////////////////////////////////
glEnable( GL_DEPTH_TEST );
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
glClearDepth( 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// Set projection and modelview matrixes
// /////////////////////////////////////////////////////////////////////////
glMatrixMode( GL_PROJECTION );
glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetProjectionMatrix() ) );
glMatrixMode( GL_MODELVIEW );
glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetViewMatrix() ) );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
// Render Model
if( m_ogl_3dmodel )
{
glPushMatrix();
double modelunit_to_3d_units_factor = m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScaled( modelunit_to_3d_units_factor,
modelunit_to_3d_units_factor,
modelunit_to_3d_units_factor );
// Center model in the render viewport
const SFVEC3F model_center = m_ogl_3dmodel->GetBBox().GetCenter();
glTranslatef( -model_center.x, -model_center.y, -model_center.z );
m_ogl_3dmodel->Draw_opaque();
m_ogl_3dmodel->Draw_transparent();
glPopMatrix();
}
// YxY squared view port
glViewport( 0, 0, clientSize.y / 8 , clientSize.y / 8 );
glClear( GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0f, 1.0f, 0.01f, RANGE_SCALE_3D * 2.0f );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
const glm::mat4 TranslationMatrix = glm::translate( glm::mat4(1.0f),
SFVEC3F( 0.0f, 0.0f, -RANGE_SCALE_3D ) );
const glm::mat4 ViewMatrix = TranslationMatrix * m_trackBallCamera.GetRotationMatrix();
glLoadMatrixf( glm::value_ptr( ViewMatrix ) );
ogl_set_arrow_material();
glColor3f( 0.9f, 0.0f, 0.0f );
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ),
SFVEC3F( RANGE_SCALE_3D / 2.65f, 0.0f, 0.0f ),
0.275f );
glColor3f( 0.0f, 0.9f, 0.0f );
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ),
SFVEC3F( 0.0f, RANGE_SCALE_3D / 2.65f, 0.0f ),
0.275f );
glColor3f( 0.0f, 0.0f, 0.9f );
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ),
SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 2.65f ),
0.275f );
// "Swaps the double-buffer of this window, making the back-buffer the
// front-buffer and vice versa, so that the output of the previous OpenGL
// commands is displayed on the window."
SwapBuffers();
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
}
void C3D_MODEL_VIEWER::OnEraseBackground( wxEraseEvent &event )
{
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnEraseBackground" ) );
// Do nothing, to avoid flashing.
}
void C3D_MODEL_VIEWER::OnMouseWheel( wxMouseEvent &event )
{
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnMouseWheel" ) );
if( event.ShiftDown() )
{
//if( event.GetWheelRotation() < 0 )
//SetView3D( WXK_UP ); // move up
//else
//SetView3D( WXK_DOWN ); // move down
}
else if( event.ControlDown() )
{
//if( event.GetWheelRotation() > 0 )
//SetView3D( WXK_RIGHT ); // move right
//else
//SetView3D( WXK_LEFT ); // move left
}
else
{
m_trackBallCamera.Zoom( event.GetWheelRotation() > 0 ? 1.1f : 1/1.1f );
//DisplayStatus();
Refresh( false );
}
m_trackBallCamera.SetCurMousePosition( event.GetPosition() );
}
#ifdef USE_OSX_MAGNIFY_EVENT
void C3D_MODEL_VIEWER::OnMagnify( wxMouseEvent& event )
{
/*
double magnification = ( event.GetMagnification() + 1.0f );
GetPrm3DVisu().m_Zoom /= magnification;
if( GetPrm3DVisu().m_Zoom <= 0.01 )
GetPrm3DVisu().m_Zoom = 0.01;
DisplayStatus();
Refresh( false );
*/
}
#endif
void C3D_MODEL_VIEWER::OnMouseMove( wxMouseEvent &event )
{
m_trackBallCamera.SetCurWindowSize( GetClientSize() );
if( event.Dragging() )
{
if( event.LeftIsDown() ) // Drag
m_trackBallCamera.Drag( event.GetPosition() );
//else if( event.MiddleIsDown() ) // Pan
// m_trackBallCamera.Pan( event.GetPosition() );
// orientation has changed, redraw mesh
Refresh( false );
}
m_trackBallCamera.SetCurMousePosition( event.GetPosition() );
}
void C3D_MODEL_VIEWER::OnLeftDown( wxMouseEvent &event )
{
//m_is_moving_mouse = true;
event.Skip();
}
void C3D_MODEL_VIEWER::OnLeftUp( wxMouseEvent &event )
{
//m_is_moving_mouse = false;
//Refresh( false );
event.Skip();
}
void C3D_MODEL_VIEWER::OnMiddleDown( wxMouseEvent &event )
{
//m_is_moving_mouse = true;
event.Skip();
}
void C3D_MODEL_VIEWER::OnMiddleUp( wxMouseEvent &event )
{
//m_is_moving_mouse = false;
//Refresh( false );
event.Skip();
}
void C3D_MODEL_VIEWER::OnRightClick( wxMouseEvent &event )
{
event.Skip();
}
@@ -0,0 +1,147 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file c3d_model_viewer.h
* @brief Implements a model viewer canvas. The propose of model viewer is to
* render 3d models that come in the original data from the files without any
* transformations.
*/
#ifndef _C3D_MODEL_VIEWER_H_
#define _C3D_MODEL_VIEWER_H_
#include "3d_rendering/ctrack_ball.h"
#include <gal/hidpi_gl_canvas.h>
class S3D_CACHE;
class C_OGL_3DMODEL;
/**
* Class C3D_MODEL_VIEWER
* Implement a canvas based on a wxGLCanvas
*/
class C3D_MODEL_VIEWER : public HIDPI_GL_CANVAS
{
public:
/**
* Creates a new 3D Canvas with a attribute list
* @param aParent = the parent creator of this canvas
* @param aAttribList = a list of openGL options created by
* COGL_ATT_LIST::GetAttributesList
*/
C3D_MODEL_VIEWER( wxWindow *aParent,
const int *aAttribList = 0,
S3D_CACHE *aCacheManager = NULL );
~C3D_MODEL_VIEWER();
/**
* @brief Set3DModel - Set this model to be displayed
* @param a3DModel - 3d model data
*/
void Set3DModel( const S3DMODEL &a3DModel );
/**
* @brief Set3DModel - Set this model to be displayed
* @param aModelPathName - 3d model path name
*/
void Set3DModel( wxString const& aModelPathName );
/**
* @brief Clear3DModel - Unloads the displayed 3d model
*/
void Clear3DModel();
private:
void ogl_initialize();
void ogl_set_arrow_material();
private:
void OnPaint( wxPaintEvent &event );
void OnEraseBackground( wxEraseEvent &event );
void OnMouseWheel( wxMouseEvent &event );
#ifdef USE_OSX_MAGNIFY_EVENT
void OnMagnify( wxMouseEvent& event );
#endif
void OnMouseMove( wxMouseEvent &event );
void OnLeftDown( wxMouseEvent &event );
void OnLeftUp( wxMouseEvent &event );
void OnMiddleUp( wxMouseEvent &event );
void OnMiddleDown( wxMouseEvent &event );
void OnRightClick( wxMouseEvent &event );
DECLARE_EVENT_TABLE()
private:
/// openGL context
wxGLContext *m_glRC;
/// Camera used in this canvas
CTRACK_BALL m_trackBallCamera;
/// Original 3d model data
const S3DMODEL *m_3d_model;
/// Class holder for 3d model to display on openGL
C_OGL_3DMODEL *m_ogl_3dmodel;
/// Flag that we have a new model and it need to be reloaded when the paint is called
bool m_reload_is_needed;
/// Flag if open gl was initialized
bool m_ogl_initialized;
/// factor to convert the model or any other items to keep it in relation to
/// the +/-RANGE_SCALE_3D
/// (it is named same as the board render for better understanding proposes)
double m_BiuTo3Dunits;
/// Optional cache manager
S3D_CACHE* m_cacheManager;
/**
* Trace mask used to enable or disable the trace output of this class.
* The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_EDA_3D_MODEL_VIEWER". See the wxWidgets documentation on wxLogTrace for
* more information.
*/
static const wxChar *m_logTrace;
};
#endif // _C3D_MODEL_VIEWER_H_
@@ -1,483 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Implements a model viewer canvas. The purpose of the model viewer is to render
* 3d models that come in the original data from the files without any transformations.
*/
#include <gal/opengl/kiglew.h> // Must be included first
#include <iostream>
#include "3d_rendering/opengl/3d_model.h"
#include "eda_3d_model_viewer.h"
#include "../3d_rendering/opengl/opengl_utils.h"
#include "../3d_cache/3d_cache.h"
#include <wx/dcclient.h>
#include <base_units.h>
#include <build_version.h>
#include <gal/opengl/gl_context_mgr.h>
#include <settings/common_settings.h>
#include <pgm_base.h>
#include <dpi_scaling_common.h>
#include <class_draw_panel_gal.h>
#include <macros.h>
/**
* Scale conversion from 3d model units to pcb units
*/
#define UNITS3D_TO_UNITSPCB ( pcbIUScale.IU_PER_MM )
/**
* Trace mask used to enable or disable the trace output of this class.
* The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_EDA_3D_MODEL_VIEWER". See the wxWidgets documentation on wxLogTrace for
* more information.
*
* @ingroup trace_env_vars
*/
const wxChar* EDA_3D_MODEL_VIEWER::m_logTrace = wxT( "KI_TRACE_EDA_3D_MODEL_VIEWER" );
BEGIN_EVENT_TABLE( EDA_3D_MODEL_VIEWER, wxGLCanvas )
EVT_PAINT( EDA_3D_MODEL_VIEWER::OnPaint )
// mouse events
EVT_LEFT_DOWN( EDA_3D_MODEL_VIEWER::OnLeftDown )
EVT_LEFT_UP( EDA_3D_MODEL_VIEWER::OnLeftUp )
EVT_MIDDLE_UP( EDA_3D_MODEL_VIEWER::OnMiddleUp )
EVT_MIDDLE_DOWN( EDA_3D_MODEL_VIEWER::OnMiddleDown)
EVT_RIGHT_DOWN( EDA_3D_MODEL_VIEWER::OnRightClick )
EVT_MOUSEWHEEL( EDA_3D_MODEL_VIEWER::OnMouseWheel )
EVT_MOTION( EDA_3D_MODEL_VIEWER::OnMouseMove )
#ifdef USE_OSX_MAGNIFY_EVENT
EVT_MAGNIFY( EDA_3D_MODEL_VIEWER::OnMagnify )
#endif
// other events
EVT_ERASE_BACKGROUND( EDA_3D_MODEL_VIEWER::OnEraseBackground )
END_EVENT_TABLE()
// This defines the range that all coord will have to be rendered.
// It will use this value to convert to a normalized value between
// -(RANGE_SCALE_3D/2) .. +(RANGE_SCALE_3D/2)
#define RANGE_SCALE_3D 8.0f
EDA_3D_MODEL_VIEWER::EDA_3D_MODEL_VIEWER( wxWindow* aParent, const wxGLAttributes& aGLAttribs,
S3D_CACHE* aCacheManager ) :
HIDPI_GL_CANVAS( EDA_DRAW_PANEL_GAL::GetVcSettings(), aParent, aGLAttribs, wxID_ANY,
wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE ),
m_trackBallCamera( RANGE_SCALE_3D * 4.0f ),
m_cacheManager( aCacheManager )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::EDA_3D_MODEL_VIEWER" ) );
m_ogl_initialized = false;
m_reload_is_needed = false;
m_ogl_3dmodel = nullptr;
m_3d_model = nullptr;
m_BiuTo3dUnits = 1.0;
m_glRC = nullptr;
}
EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER()
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER" ) );
GL_CONTEXT_MANAGER* gl_mgr = Pgm().GetGLContextManager();
if( m_glRC )
{
gl_mgr->LockCtx( m_glRC, this );
delete m_ogl_3dmodel;
m_ogl_3dmodel = nullptr;
gl_mgr->UnlockCtx( m_glRC );
gl_mgr->DestroyCtx( m_glRC );
}
}
void EDA_3D_MODEL_VIEWER::Set3DModel( const S3DMODEL& a3DModel )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::Set3DModel with a S3DMODEL" ) );
// Validate a3DModel pointers
wxASSERT( a3DModel.m_Materials != nullptr );
wxASSERT( a3DModel.m_Meshes != nullptr );
wxASSERT( a3DModel.m_MaterialsSize > 0 );
wxASSERT( a3DModel.m_MeshesSize > 0 );
// Delete the old model
delete m_ogl_3dmodel;
m_ogl_3dmodel = nullptr;
m_3d_model = nullptr;
if( ( a3DModel.m_Materials != nullptr ) && ( a3DModel.m_Meshes != nullptr )
&& ( a3DModel.m_MaterialsSize > 0 ) && ( a3DModel.m_MeshesSize > 0 ) )
{
m_3d_model = &a3DModel;
m_reload_is_needed = true;
}
Refresh();
}
void EDA_3D_MODEL_VIEWER::Set3DModel( const wxString& aModelPathName)
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::Set3DModel with a wxString" ) );
if( m_cacheManager )
{
const S3DMODEL* model = m_cacheManager->GetModel( aModelPathName, wxEmptyString, nullptr );
if( model )
Set3DModel( (const S3DMODEL &)*model );
else
Clear3DModel();
}
}
void EDA_3D_MODEL_VIEWER::Clear3DModel()
{
// Delete the old model
m_reload_is_needed = false;
delete m_ogl_3dmodel;
m_ogl_3dmodel = nullptr;
m_3d_model = nullptr;
Refresh();
}
void EDA_3D_MODEL_VIEWER::ogl_initialize()
{
const GLenum err = glewInit();
if( GLEW_OK != err )
{
const wxString msgError = (const char*) glewGetErrorString( err );
wxLogMessage( msgError );
}
else
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::ogl_initialize Using GLEW version %s" ),
From_UTF8( (char*) glewGetString( GLEW_VERSION ) ) );
}
SetOpenGLInfo( (const char*) glGetString( GL_VENDOR ), (const char*) glGetString( GL_RENDERER ),
(const char*) glGetString( GL_VERSION ) );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
glEnable( GL_DEPTH_TEST );
glEnable( GL_CULL_FACE );
glShadeModel( GL_SMOOTH );
glEnable( GL_LINE_SMOOTH );
glEnable( GL_NORMALIZE );
// Setup light
// https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
const GLfloat ambient[] = { 0.01f, 0.01f, 0.01f, 1.0f };
const GLfloat diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
// defines a directional light that points along the negative z-axis
const GLfloat position[] = { 0.0f, 0.0f, 2.0f * RANGE_SCALE_3D, 0.0f };
const GLfloat lmodel_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
glLightfv( GL_LIGHT0, GL_SPECULAR, specular );
glLightfv( GL_LIGHT0, GL_POSITION, position );
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient );
}
void EDA_3D_MODEL_VIEWER::ogl_set_arrow_material()
{
glEnable( GL_COLOR_MATERIAL );
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
const SFVEC4F specular = SFVEC4F( 0.1f, 0.1f, 0.1f, 1.0f );
glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 96.0f );
}
void EDA_3D_MODEL_VIEWER::OnPaint( wxPaintEvent& event )
{
event.Skip( false );
// SwapBuffer requires the window to be shown before calling
if( !IsShownOnScreen() )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnPaint !IsShown" ) );
return;
}
// "Makes the OpenGL state that is represented by the OpenGL rendering
// context context current, i.e. it will be used by all subsequent OpenGL calls.
// This function may only be called when the window is shown on screen"
if( m_glRC == nullptr )
m_glRC = Pgm().GetGLContextManager()->CreateCtx( this );
// CreateCtx could and does fail per sentry crash events, lets be graceful
if( m_glRC == nullptr )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnPaint creating gl context failed" ) );
return;
}
Pgm().GetGLContextManager()->LockCtx( m_glRC, this );
// Set the OpenGL viewport according to the client size of this canvas.
// This is done here rather than in a wxSizeEvent handler because our
// OpenGL rendering context (and thus viewport setting) is used with
// multiple canvases: If we updated the viewport in the wxSizeEvent
// handler, changing the size of one canvas causes a viewport setting that
// is wrong when next another canvas is repainted.
wxSize clientSize = GetNativePixelSize();
if( !m_ogl_initialized )
{
m_ogl_initialized = true;
ogl_initialize();
}
if( m_reload_is_needed )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnPaint m_reload_is_needed" ) );
m_reload_is_needed = false;
m_ogl_3dmodel = new MODEL_3D( *m_3d_model, MATERIAL_MODE::NORMAL );
// It convert a model as it was a board, so get the max size dimension of the board
// and compute the conversion scale
m_BiuTo3dUnits =
(double) RANGE_SCALE_3D
/ ( (double) m_ogl_3dmodel->GetBBox().GetMaxDimension() * UNITS3D_TO_UNITSPCB );
}
glViewport( 0, 0, clientSize.x, clientSize.y );
m_trackBallCamera.SetCurWindowSize( clientSize );
// clear color and depth buffers
glEnable( GL_DEPTH_TEST );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClearDepth( 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// Set projection and modelview matrices
glMatrixMode( GL_PROJECTION );
glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetProjectionMatrix() ) );
glMatrixMode( GL_MODELVIEW );
glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetViewMatrix() ) );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
// Render Model
if( m_ogl_3dmodel )
{
glPushMatrix();
double modelunit_to_3d_units_factor = m_BiuTo3dUnits * UNITS3D_TO_UNITSPCB;
glScaled( modelunit_to_3d_units_factor, modelunit_to_3d_units_factor,
modelunit_to_3d_units_factor );
// Center model in the render viewport
const SFVEC3F model_center = m_ogl_3dmodel->GetBBox().GetCenter();
glTranslatef( -model_center.x, -model_center.y, -model_center.z );
m_ogl_3dmodel->BeginDrawMulti( true );
m_ogl_3dmodel->DrawOpaque( false );
glDepthMask( GL_FALSE );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
m_ogl_3dmodel->DrawTransparent( 1.0f, false );
glDisable( GL_BLEND );
glDepthMask( GL_TRUE );
m_ogl_3dmodel->EndDrawMulti();
glPopMatrix();
}
// YxY squared view port
glViewport( 0, 0, clientSize.y / 8 , clientSize.y / 8 );
glClear( GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0f, 1.0f, 0.01f, RANGE_SCALE_3D * 2.0f );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
const glm::mat4 TranslationMatrix = glm::translate( glm::mat4(1.0f),
SFVEC3F( 0.0f, 0.0f, -RANGE_SCALE_3D ) );
const glm::mat4 ViewMatrix = TranslationMatrix * m_trackBallCamera.GetRotationMatrix();
glLoadMatrixf( glm::value_ptr( ViewMatrix ) );
ogl_set_arrow_material();
glColor3f( 0.9f, 0.0f, 0.0f );
DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( RANGE_SCALE_3D / 2.65f, 0.0f, 0.0f ),
0.275f );
glColor3f( 0.0f, 0.9f, 0.0f );
DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, RANGE_SCALE_3D / 2.65f, 0.0f ),
0.275f );
glColor3f( 0.0f, 0.0f, 0.9f );
DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 2.65f ),
0.275f );
// "Swaps the double-buffer of this window, making the back-buffer the
// front-buffer and vice versa, so that the output of the previous OpenGL
// commands is displayed on the window."
SwapBuffers();
Pgm().GetGLContextManager()->UnlockCtx( m_glRC );
}
void EDA_3D_MODEL_VIEWER::OnEraseBackground( wxEraseEvent& event )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnEraseBackground" ) );
// Do nothing, to avoid flashing.
}
void EDA_3D_MODEL_VIEWER::OnMouseWheel( wxMouseEvent& event )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnMouseWheel" ) );
if( event.ShiftDown() )
{
//if( event.GetWheelRotation() < 0 )
//SetView3D( VIEW_3D_TYPE::VIEW3D_PAN_UP ); // move up
//else
//SetView3D( VIEW_3D_TYPE::VIEW3D_PAN_DOWN ); // move down
}
else if( event.ControlDown() )
{
//if( event.GetWheelRotation() > 0 )
//SetView3D( VIEW_3D_TYPE::VIEW3D_PAN_RIGHT ); // move right
//else
//SetView3D( VIEW_3D_TYPE::VIEW3D_PAN_LEFT ); // move left
}
else
{
m_trackBallCamera.Zoom( event.GetWheelRotation() > 0 ? 1.1f : 1/1.1f );
//DisplayStatus();
Refresh( false );
}
m_trackBallCamera.SetCurMousePosition( event.GetPosition() );
}
#ifdef USE_OSX_MAGNIFY_EVENT
void EDA_3D_MODEL_VIEWER::OnMagnify( wxMouseEvent& event )
{
}
#endif
void EDA_3D_MODEL_VIEWER::OnMouseMove( wxMouseEvent& event )
{
const wxSize& nativeWinSize = GetNativePixelSize();
const wxPoint& nativePosition = GetNativePosition( event.GetPosition() );
m_trackBallCamera.SetCurWindowSize( nativeWinSize );
if( event.Dragging() )
{
if( event.LeftIsDown() ) // Drag
m_trackBallCamera.Drag( nativePosition );
// orientation has changed, redraw mesh
Refresh( false );
}
m_trackBallCamera.SetCurMousePosition( nativePosition );
}
void EDA_3D_MODEL_VIEWER::OnLeftDown( wxMouseEvent& event )
{
event.Skip();
}
void EDA_3D_MODEL_VIEWER::OnLeftUp( wxMouseEvent& event )
{
event.Skip();
}
void EDA_3D_MODEL_VIEWER::OnMiddleDown( wxMouseEvent& event )
{
event.Skip();
}
void EDA_3D_MODEL_VIEWER::OnMiddleUp( wxMouseEvent& event )
{
event.Skip();
}
void EDA_3D_MODEL_VIEWER::OnRightClick( wxMouseEvent& event )
{
event.Skip();
}
@@ -1,143 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file eda_3d_model_viewer.h
* @brief Implements a model viewer canvas.
*
* The purpose of model viewer is to render 3d models that come in the original data from
* the files without any transformations.
*/
#ifndef _C3D_MODEL_VIEWER_H_
#define _C3D_MODEL_VIEWER_H_
#include "3d_rendering/track_ball.h"
#include <gal/hidpi_gl_canvas.h>
class S3D_CACHE;
class MODEL_3D;
/**
* Implement a canvas based on a wxGLCanvas.
*/
class EDA_3D_MODEL_VIEWER : public HIDPI_GL_CANVAS
{
public:
/**
* Create a new 3D Canvas with a attribute list.
*
* @param aParent the parent creator of this canvas.
* @param aGLAttribs openGL attributes created by #OGL_ATT_LIST::GetAttributesList.
*/
EDA_3D_MODEL_VIEWER( wxWindow* aParent, const wxGLAttributes& aGLAttribs,
S3D_CACHE* aCacheManager = nullptr );
~EDA_3D_MODEL_VIEWER();
/**
* Set this model to be displayed.
*
* @param a3DModel 3D model data.
*/
void Set3DModel( const S3DMODEL& a3DModel );
/**
* Set this model to be displayed.
*
* N.B. This will not load a model from the internal cache. Only from on disk.
*
* @param aModelPathName 3D model path name. Must be a file on disk.
*/
void Set3DModel( const wxString& aModelPathName );
/**
* Unload the displayed 3D model.
*/
void Clear3DModel();
private:
void ogl_initialize();
void ogl_set_arrow_material();
void OnPaint( wxPaintEvent& event );
void OnEraseBackground( wxEraseEvent& event );
void OnMouseWheel( wxMouseEvent& event );
#ifdef USE_OSX_MAGNIFY_EVENT
void OnMagnify( wxMouseEvent& event );
#endif
void OnMouseMove( wxMouseEvent& event );
void OnLeftDown( wxMouseEvent& event );
void OnLeftUp( wxMouseEvent& event );
void OnMiddleUp( wxMouseEvent& event );
void OnMiddleDown( wxMouseEvent& event );
void OnRightClick( wxMouseEvent& event );
DECLARE_EVENT_TABLE()
/// openGL context
wxGLContext* m_glRC;
/// Camera used in this canvas
TRACK_BALL m_trackBallCamera;
/// Original 3d model data
const S3DMODEL* m_3d_model;
/// Class holder for 3d model to display on openGL
MODEL_3D* m_ogl_3dmodel;
/// Flag that we have a new model and it need to be reloaded when the paint is called
bool m_reload_is_needed;
/// Flag if open gl was initialized
bool m_ogl_initialized;
/// factor to convert the model or any other items to keep it in relation to
/// the +/-RANGE_SCALE_3D
/// (it is named same as the board render for better understanding proposes)
double m_BiuTo3dUnits;
/// Optional cache manager
S3D_CACHE* m_cacheManager;
/**
* Trace mask used to enable or disable the trace output of this class.
* The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_EDA_3D_MODEL_VIEWER". See the wxWidgets documentation on wxLogTrace for
* more information.
*/
static const wxChar* m_logTrace;
};
#endif // _C3D_MODEL_VIEWER_H_
-27
View File
@@ -1,27 +0,0 @@
add_library(3d-viewer_navlib STATIC
"nl_3d_viewer_plugin.cpp"
"nl_3d_viewer_plugin_impl.cpp"
"nl_footprint_properties_plugin.cpp"
"nl_footprint_properties_plugin_impl.cpp"
)
# 3d-viewer_navlib depends on make_lexer outputs in common
add_dependencies( 3d-viewer_navlib pcbcommon )
# Find the 3DxWare SDK component 3DxWare::NlClient
# find_package(TDxWare_SDK 4.0 REQUIRED COMPONENTS 3DxWare::Navlib)
target_compile_definitions(3d-viewer_navlib PRIVATE
$<TARGET_PROPERTY:3DxWare::Navlib,INTERFACE_COMPILE_DEFINITIONS>
)
target_compile_options(3d-viewer_navlib PRIVATE
$<TARGET_PROPERTY:3DxWare::Navlib,INTERFACE_COMPILE_OPTIONS>
)
target_include_directories(3d-viewer_navlib PRIVATE
$<TARGET_PROPERTY:3DxWare::Navlib,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:pcbnew_kiface_objects,INCLUDE_DIRECTORIES>
)
target_link_libraries(3d-viewer_navlib
$<TARGET_PROPERTY:3DxWare::Navlib,INTERFACE_LINK_LIBRARIES>
3DxWare::Navlib
)
@@ -1,45 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2021 3Dconnexion
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nl_3d_viewer_plugin.h"
#include "nl_3d_viewer_plugin_impl.h"
#include <advanced_config.h>
#include <kiplatform/drivers.h>
NL_3D_VIEWER_PLUGIN::NL_3D_VIEWER_PLUGIN( EDA_3D_CANVAS* aViewport )
{
if( ADVANCED_CFG::GetCfg().m_Use3DConnexionDriver
&& KIPLATFORM::DRIVERS::Valid3DConnexionDriverVersion() )
{
m_impl = std::make_unique<NL_3D_VIEWER_PLUGIN_IMPL>( aViewport, "KiCAD 3D" );
m_impl->Connect();
}
}
NL_3D_VIEWER_PLUGIN::~NL_3D_VIEWER_PLUGIN() = default;
void NL_3D_VIEWER_PLUGIN::SetFocus( bool focus )
{
if( m_impl )
m_impl->SetFocus( focus );
}
-62
View File
@@ -1,62 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2021 3Dconnexion
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file nl_3d_viewer_plugin.h
* @brief Declaration of the NL_3D_VIEWER_PLUGIN class
*/
#ifndef NL_3D_VIEWER_PLUGIN_H_
#define NL_3D_VIEWER_PLUGIN_H_
#include <memory>
// Forward declarations.
class EDA_3D_CANVAS;
class NL_3D_VIEWER_PLUGIN_IMPL;
/**
* The class that implements the public interface to the SpaceMouse plug-in.
*/
class NL_3D_VIEWER_PLUGIN
{
public:
/**
* Initializes a new instance of the NL_3D_VIEWER_PLUGIN.
*
* @param aViewport is the viewport to be navigated.
*/
NL_3D_VIEWER_PLUGIN( EDA_3D_CANVAS* aViewport );
virtual ~NL_3D_VIEWER_PLUGIN();
/**
* Set the connection to the 3Dconnexion driver to the focus state so that
* 3DMouse data is routed here.
*
* @param aFocus is true to set the connection active.
*/
void SetFocus( bool aFocus = true );
private:
std::unique_ptr<NL_3D_VIEWER_PLUGIN_IMPL> m_impl;
};
#endif // NL_3D_VIEWER_PLUGIN_H_
@@ -1,663 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2024 3Dconnexion
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nl_3d_viewer_plugin_impl.h"
// 3d-viewer
#include <3d-viewer/3d_rendering/track_ball.h>
#include <3d-viewer/3d_canvas/eda_3d_canvas.h>
// KiCad includes
#include <tool/action_manager.h>
#include <tool/tool_manager.h>
#include <tool/tools_holder.h>
// stdlib
#include <map>
#include <string>
#include <vector>
#include <wx/mstream.h>
/**
* Flag to enable the NL_3D_VIEWER_PLUGIN debug tracing.
*
* Use "KI_TRACE_NL_3D_VIEWER_PLUGIN" to enable.
*
* @ingroup trace_env_vars
*/
const wxChar* NL_3D_VIEWER_PLUGIN_IMPL::m_logTrace = wxT( "KI_TRACE_NL_3D_VIEWER_PLUGIN" );
/**
* Template to compare two glm::mat<T> values for equality within a required epsilon.
*
* @param aFirst value to compare.
* @param aSecond value to compare.
* @param aEpsilon allowed error.
* @return true if the values considered equal within the specified epsilon, otherwise false.
*/
template <glm::length_t L, glm::length_t C, class T, glm::qualifier Q>
bool equals( glm::mat<L, C, T, Q> const& aFirst, glm::mat<L, C, T, Q> const& aSecond,
T aEpsilon = static_cast<T>( FLT_EPSILON * 10 ) )
{
T const* first = glm::value_ptr( aFirst );
T const* second = glm::value_ptr( aSecond );
for( glm::length_t j = 0; j < L * C; ++j )
{
if( !equals( first[j], second[j], aEpsilon ) )
{
return false;
}
}
return true;
}
NL_3D_VIEWER_PLUGIN_IMPL::NL_3D_VIEWER_PLUGIN_IMPL( EDA_3D_CANVAS* aCanvas,
const std::string& aProfileHint ) :
NAV_3D( false, false ),
m_canvas( aCanvas ),
m_capIsMoving( false ),
m_newWidth( 0.0 )
{
m_camera = dynamic_cast<TRACK_BALL*>( m_canvas->GetCamera() );
PutProfileHint( aProfileHint );
}
NL_3D_VIEWER_PLUGIN_IMPL::~NL_3D_VIEWER_PLUGIN_IMPL()
{
EnableNavigation( false );
}
void NL_3D_VIEWER_PLUGIN_IMPL::SetFocus( bool aFocus )
{
wxLogTrace( m_logTrace, wxT( "NL_3D_VIEWER_PLUGIN_IMPL::SetFocus %d" ), aFocus );
NAV_3D::Write( navlib::focus_k, aFocus );
}
EDA_3D_CANVAS* NL_3D_VIEWER_PLUGIN_IMPL::GetCanvas() const
{
return m_canvas;
}
void NL_3D_VIEWER_PLUGIN_IMPL::Connect()
{
EnableNavigation(true);
PutFrameTimingSource(TimingSource::SpaceMouse);
exportCommandsAndImages();
}
CATEGORY_STORE::iterator add_category( std::string aCategoryPath, CATEGORY_STORE& aCategoryStore )
{
using TDx::SpaceMouse::CCategory;
CATEGORY_STORE::iterator parent_iter = aCategoryStore.begin();
std::string::size_type pos = aCategoryPath.find_last_of( '.' );
if( pos != std::string::npos )
{
std::string parentPath = aCategoryPath.substr( 0, pos );
parent_iter = aCategoryStore.find( parentPath );
if( parent_iter == aCategoryStore.end() )
{
parent_iter = add_category( parentPath, aCategoryStore );
}
}
std::string name = aCategoryPath.substr( pos + 1 );
std::unique_ptr<CCategory> categoryNode =
std::make_unique<CCategory>( aCategoryPath.c_str(), name.c_str() );
CATEGORY_STORE::iterator iter = aCategoryStore.insert(
aCategoryStore.end(), CATEGORY_STORE::value_type( aCategoryPath, categoryNode.get() ) );
parent_iter->second->push_back( std::move( categoryNode ) );
return iter;
}
void NL_3D_VIEWER_PLUGIN_IMPL::exportCommandsAndImages()
{
wxLogTrace( m_logTrace, wxT( "NL_3D_VIEWER_PLUGIN_IMPL::exportCommandsAndImages" ) );
std::list<TOOL_ACTION*> actions = ACTION_MANAGER::GetActionList();
if( actions.size() == 0 )
{
return;
}
using TDx::SpaceMouse::CCommand;
using TDx::SpaceMouse::CCommandSet;
// The root action set node
CCommandSet commandSet( "EDA_3D_CANVAS", "3D Viewer" );
// Activate the command set
NAV_3D::PutActiveCommands( commandSet.GetId() );
// temporary store for the categories
CATEGORY_STORE categoryStore;
std::vector<TDx::CImage> vImages;
// add the action set to the category_store
categoryStore.insert( categoryStore.end(), CATEGORY_STORE::value_type( ".", &commandSet ) );
std::list<TOOL_ACTION*>::const_iterator it;
for( it = actions.begin(); it != actions.end(); ++it )
{
const TOOL_ACTION* action = *it;
std::string label = action->GetMenuLabel().ToStdString();
if( label.empty() )
{
continue;
}
std::string name = action->GetName();
// Do no export commands for the Pcbnew app.
if( name.rfind( "pcbnew.", 0 ) == 0 )
{
continue;
}
std::string strCategory = action->GetToolName();
CATEGORY_STORE::iterator iter = categoryStore.find( strCategory );
if( iter == categoryStore.end() )
{
iter = add_category( std::move( strCategory ), categoryStore );
}
std::string description = action->GetDescription().ToStdString();
// Arbitrary 8-bit data stream
wxMemoryOutputStream imageStream;
if( action->GetIcon() != BITMAPS::INVALID_BITMAP )
{
wxImage image = KiBitmap( action->GetIcon() ).ConvertToImage();
image.SaveFile( imageStream, wxBitmapType::wxBITMAP_TYPE_PNG );
image.Destroy();
if( imageStream.GetSize() )
{
wxStreamBuffer* streamBuffer = imageStream.GetOutputStreamBuffer();
TDx::CImage tdxImage = TDx::CImage::FromData( "", 0, name.c_str() );
tdxImage.AssignImage( std::string( reinterpret_cast<const char*>(
streamBuffer->GetBufferStart() ),
streamBuffer->GetBufferSize() ),
0 );
wxLogTrace( m_logTrace, wxT( "Adding image for : %s" ), name );
vImages.push_back( std::move( tdxImage ) );
}
}
wxLogTrace( m_logTrace, wxT( "Inserting command: %s, description: %s, in category: %s" ),
name, description, iter->first );
iter->second->push_back(
CCommand( std::move( name ), std::move( label ), std::move( description ) ) );
}
NAV_3D::AddCommandSet( commandSet );
NAV_3D::AddImages( vImages );
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetCameraMatrix( navlib::matrix_t& matrix ) const
{
// cache the camera matrix so that we can tell if the view has been moved and
// calculate a delta transform if required.
m_cameraMatrix = m_camera->GetViewMatrix();
std::copy_n( glm::value_ptr( glm::inverse( m_cameraMatrix ) ), 16, matrix.m );
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetPointerPosition( navlib::point_t& position ) const
{
SFVEC3F origin, direction;
m_camera->MakeRayAtCurrentMousePosition( origin, direction );
position = { origin.x, origin.y, origin.z };
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetViewExtents( navlib::box_t& extents ) const
{
if( m_camera->GetProjection() == PROJECTION_TYPE::PERSPECTIVE )
{
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
}
const CAMERA_FRUSTUM& f = m_camera->GetFrustum();
double half_width = f.fw / 2.;
double half_height = f.fh / 2.;
extents = { -half_width, -half_height, f.nearD, half_width, half_height, f.farD };
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetViewFOV( double& aFov ) const
{
const CAMERA_FRUSTUM& f = m_camera->GetFrustum();
aFov = glm::radians( f.angle );
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetViewFrustum( navlib::frustum_t& aFrustum ) const
{
if( m_camera->GetProjection() != PROJECTION_TYPE::PERSPECTIVE )
{
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
}
const CAMERA_FRUSTUM& f = m_camera->GetFrustum();
double half_width = f.nw / 2.;
double half_height = f.nh / 2.;
aFrustum = { -half_width, half_width, -half_height, half_height, f.nearD, f.farD };
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetIsViewPerspective( navlib::bool_t& perspective ) const
{
perspective = m_camera->GetProjection() == PROJECTION_TYPE::PERSPECTIVE ? 1 : 0;
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetCameraMatrix( const navlib::matrix_t& aCameraMatrix )
{
long result = 0;
glm::mat4 cam, viewMatrix;
std::copy_n( aCameraMatrix.m, 16, glm::value_ptr( cam ) );
viewMatrix = glm::inverse( cam );
glm::mat4 camera = m_camera->GetViewMatrix();
// The navlib does not move the camera in its z-axis in an orthographic projection
// as this does not change the viewed object size. However ...
if( m_camera->GetProjection() == PROJECTION_TYPE::ORTHO )
{
// ... the CAMERA class couples zoom and distance to the object: we need to
// ensure that The CAMERA's z position relative to the lookat_pos is not changed
// in an orthographic projection.
glm::vec4 lookat( m_camera->GetLookAtPos(), 1.0f );
glm::vec4 lookat_new = viewMatrix * lookat;
glm::vec4 lookat_old = camera * lookat;
viewMatrix[3].z += lookat_old.z - lookat_new.z;
}
if( !equals( camera, m_cameraMatrix ) )
{
// Some other input device has moved the camera. Apply only the intended delta
// transform ...
m_camera->SetViewMatrix( viewMatrix * glm::inverse( m_cameraMatrix ) * camera );
m_camera->Update();
// .., cache the intended camera matrix so that we can calculate the delta
// transform when needed ...
m_cameraMatrix = viewMatrix;
// ... and let the 3DMouse controller know, that something is amiss.
return navlib::make_result_code( navlib::navlib_errc::error );
}
m_camera->SetViewMatrix( viewMatrix );
m_camera->Update();
// cache the view matrix so that we know when it has changed.
m_cameraMatrix = m_camera->GetViewMatrix();
// The camera has a constraint on the z position so we need to check that ...
if( !equals( m_cameraMatrix[3].z, viewMatrix[3].z ) )
{
// ... and let the 3DMouse controller know, when something is amiss.
return navlib::make_result_code( navlib::navlib_errc::error );
}
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetViewExtents( const navlib::box_t& extents )
{
const CAMERA_FRUSTUM& f = m_camera->GetFrustum();
float factor = f.nw / ( extents.max_x - extents.min_x );
float zoom = m_camera->GetZoom() / factor;
m_camera->Zoom( factor );
// The camera auto positions the camera to match the zoom values. We need to
// update our cached camera matrix to match the new z value
m_cameraMatrix[3].z = m_camera->GetViewMatrix()[3].z;
// The camera has a constraint on the zoom factor so we need to check that ...
if( zoom != m_camera->GetZoom() )
{
// ... and let the 3DMouse controller know, when something is amiss.
return navlib::make_result_code( navlib::navlib_errc::error );
}
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetViewFOV( double fov )
{
return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetViewFrustum( const navlib::frustum_t& frustum )
{
return navlib::make_result_code( navlib::navlib_errc::permission_denied );
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetModelExtents( navlib::box_t& extents ) const
{
SFVEC3F min = m_canvas->GetBoardAdapter().GetBBox().Min();
SFVEC3F max = m_canvas->GetBoardAdapter().GetBBox().Max();
extents = { min.x, min.y, min.z, max.x, max.y, max.z };
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetSelectionExtents( navlib::box_t& extents ) const
{
return navlib::make_result_code( navlib::navlib_errc::no_data_available );
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetSelectionTransform( navlib::matrix_t& transform ) const
{
return navlib::make_result_code( navlib::navlib_errc::no_data_available );
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetIsSelectionEmpty( navlib::bool_t& empty ) const
{
empty = true;
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetSelectionTransform( const navlib::matrix_t& matrix )
{
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetPivotPosition( navlib::point_t& position ) const
{
SFVEC3F lap = m_camera->GetLookAtPos();
position = { lap.x, lap.y, lap.z };
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::IsUserPivot( navlib::bool_t& userPivot ) const
{
userPivot = false;
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetPivotPosition( const navlib::point_t& position )
{
SFVEC3F pivotPos = SFVEC3F( position.x, position.y, position.z );
// Set the 3dmouse pivot position.
m_canvas->Set3dmousePivotPos( pivotPos );
// Set the camera lookat pos.
m_camera->SetLookAtPos_T1( pivotPos );
m_canvas->Request_refresh();
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetPivotVisible( navlib::bool_t& visible ) const
{
visible = m_canvas->GetRender3dmousePivot();
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetPivotVisible( bool visible )
{
m_canvas->SetRender3dmousePivot( visible );
m_canvas->Request_refresh();
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetHitLookAt( navlib::point_t& position ) const
{
RAY mouseRay;
mouseRay.Init( m_rayOrigin, m_rayDirection );
float hit;
glm::vec3 vec;
// Test it with the board bounding box
if( m_canvas->GetBoardAdapter().GetBBox().Intersect( mouseRay, &hit ) )
{
vec = mouseRay.at( hit );
position = { vec.x, vec.y, vec.z };
return 0;
}
return navlib::make_result_code( navlib::navlib_errc::no_data_available );
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetHitAperture( double aperture )
{
return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetHitDirection( const navlib::vector_t& direction )
{
m_rayDirection = { direction.x, direction.y, direction.z };
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetHitLookFrom( const navlib::point_t& eye )
{
m_rayOrigin = { eye.x, eye.y, eye.z };
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetHitSelectionOnly( bool onlySelection )
{
return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetActiveCommand( std::string commandId )
{
if( commandId.empty() )
{
return 0;
}
std::list<TOOL_ACTION*> actions = ACTION_MANAGER::GetActionList();
TOOL_ACTION* context = nullptr;
for( std::list<TOOL_ACTION*>::const_iterator it = actions.begin(); it != actions.end(); it++ )
{
TOOL_ACTION* action = *it;
std::string nm = action->GetName();
if( commandId == nm )
{
context = action;
}
}
if( context != nullptr )
{
wxWindow* parent = m_canvas->GetParent();
// Only allow command execution if the window is enabled. i.e. there is not a modal dialog
// currently active.
TOOLS_HOLDER* tools_holder = nullptr;
if( parent->IsEnabled() && ( tools_holder = dynamic_cast<TOOLS_HOLDER*>( parent ) ) )
{
TOOL_MANAGER* tool_manager = tools_holder->GetToolManager();
if( tool_manager == nullptr )
{
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
}
// Get the selection to use to test if the action is enabled
SELECTION& sel = tool_manager->GetToolHolder()->GetCurrentSelection();
bool runAction = true;
if( const ACTION_CONDITIONS* aCond =
tool_manager->GetActionManager()->GetCondition( *context ) )
{
runAction = aCond->enableCondition( sel );
}
if( runAction )
{
tool_manager->RunAction( *context );
m_canvas->Request_refresh();
}
}
else
{
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
}
}
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetSettingsChanged( long change )
{
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetMotionFlag( bool value )
{
m_capIsMoving = value;
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetTransaction( long value )
{
if( value != 0L )
{
}
else
{
m_canvas->Request_refresh( true );
wxLogTrace( m_logTrace, wxT( "End of transaction" ) );
}
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::SetCameraTarget( const navlib::point_t& position )
{
return navlib::make_result_code( navlib::navlib_errc::function_not_supported );
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetFrontView( navlib::matrix_t& matrix ) const
{
matrix = { 1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1 };
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetCoordinateSystem( navlib::matrix_t& matrix ) const
{
// Use the right-handed coordinate system X-right, Z-up, Y-in (row vectors)
matrix = { 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1 };
return 0;
}
long NL_3D_VIEWER_PLUGIN_IMPL::GetIsViewRotatable( navlib::bool_t& isRotatable ) const
{
isRotatable = true;
return 0;
}
@@ -1,162 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2024 3Dconnexion
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file nl_3d_viewer_plugin_impl.h
* @brief Declaration of the NL_3D_VIEWER_PLUGIN_IMPL class
*/
#ifndef NL_3D_VIEWER_PLUGIN_IMPL_H_
#define NL_3D_VIEWER_PLUGIN_IMPL_H_
// TDxWare SDK.
#include <SpaceMouse/CNavigation3D.hpp>
// KiCad
#include <include/plugins/3dapi/xv3d_types.h>
// wx
#include <wx/chartype.h>
// glm
#include <glm/glm.hpp>
// Forward declarations.
class EDA_3D_CANVAS;
class TRACK_BALL;
// temporary store for the categories
typedef std::map<std::string, TDx::CCommandTreeNode*> CATEGORY_STORE;
/**
* Add a category to the store.
*
* The function adds category paths of the format "A.B" where B is a sub-category of A.
*
* @param aCategoryPath is the std::string representation of the category.
* @param aCategoryStore is the CATEGORY_STORE instance to add to.
* @return a CATEGORY_STORE::iterator where the category was added.
*/
CATEGORY_STORE::iterator add_category( std::string aCategoryPath, CATEGORY_STORE& aCategoryStore );
// Convenience typedef.
typedef TDx::SpaceMouse::Navigation3D::CNavigation3D NAV_3D;
/**
* The class that implements the accessors and mutators required for
* 3D navigation in an EDA_3D_CANVAS using a SpaceMouse.
*/
class NL_3D_VIEWER_PLUGIN_IMPL : public NAV_3D
{
public:
/**
* Initializes a new instance of the NL_3DVIEWER_PLUGIN.
*
* @param aCanvas is the viewport to be navigated.
* @param aProfileHint tells the 3DConnexion UI which profile to use.
*/
NL_3D_VIEWER_PLUGIN_IMPL( EDA_3D_CANVAS* aCanvas, const std::string& aProfileHint );
virtual ~NL_3D_VIEWER_PLUGIN_IMPL();
/**
* Set the connection to the 3Dconnexion driver to the focus state so that
* 3DMouse data is routed here.
*
* @param aFocus is true to set the connection active.
*/
void SetFocus( bool aFocus = true );
/**
* Get the m_canvas pointer.
*/
EDA_3D_CANVAS* GetCanvas() const;
/**
* Connect plugin implementation to the driver.
*/
void Connect();
private:
/**
* Export the invocable actions and images to the 3Dconnexion UI.
*/
virtual void exportCommandsAndImages();
long GetCameraMatrix( navlib::matrix_t& aMatrix ) const override;
long GetPointerPosition( navlib::point_t& aPosition ) const override;
long GetViewExtents( navlib::box_t& aExtents ) const override;
long GetViewFOV( double& aFov ) const override;
long GetViewFrustum( navlib::frustum_t& aFrustum ) const override;
long GetIsViewPerspective( navlib::bool_t& aPerspective ) const override;
long SetCameraMatrix( const navlib::matrix_t& aMatrix ) override;
long SetViewExtents( const navlib::box_t& aExtents ) override;
long SetViewFOV( double aFov ) override;
long SetViewFrustum( const navlib::frustum_t& aFrustum ) override;
long GetModelExtents( navlib::box_t& aExtents ) const override;
long GetSelectionExtents( navlib::box_t& aExtents ) const override;
long GetSelectionTransform( navlib::matrix_t& aTransform ) const override;
long GetIsSelectionEmpty( navlib::bool_t& aEmpty ) const override;
long SetSelectionTransform( const navlib::matrix_t& aMatrix ) override;
long GetPivotPosition( navlib::point_t& aPosition ) const override;
long IsUserPivot( navlib::bool_t& aUserPivot ) const override;
long SetPivotPosition( const navlib::point_t& aPosition ) override;
long GetPivotVisible( navlib::bool_t& aVisible ) const override;
long SetPivotVisible( bool aVisible ) override;
long GetHitLookAt( navlib::point_t& aPosition ) const override;
long SetHitAperture( double aAperture ) override;
long SetHitDirection( const navlib::vector_t& aDirection ) override;
long SetHitLookFrom( const navlib::point_t& aPosition ) override;
long SetHitSelectionOnly( bool aSelectionOnly ) override;
long SetActiveCommand( std::string aCommandId ) override;
long SetSettingsChanged( long aChangeNumber ) override;
long SetMotionFlag( bool aValue ) override;
long SetTransaction( long aValue ) override;
long SetCameraTarget( const navlib::point_t& aPosition ) override;
long GetFrontView( navlib::matrix_t& aMatrix ) const override;
long GetCoordinateSystem( navlib::matrix_t& aMatrix ) const override;
long GetIsViewRotatable( navlib::bool_t& isRotatable ) const override;
private:
EDA_3D_CANVAS* m_canvas;
TRACK_BALL* m_camera;
bool m_capIsMoving;
double m_newWidth;
SFVEC3F m_rayOrigin;
SFVEC3F m_rayDirection;
// The cached CAMERA affine matrix. This is used to determine if the camera has been
// moved. The camera matrix is the world to camera affine.
mutable glm::mat4 m_cameraMatrix;
/**
* Trace mask used to enable or disable the trace output of this class.
* The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_NL_3DVIEWER_PLUGIN". See the wxWidgets documentation on wxLogTrace for
* more information.
*/
static const wxChar* m_logTrace;
};
#endif // NL_3D_VIEWER_PLUGIN_IMPL_H_
@@ -1,45 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2024 3Dconnexion
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nl_footprint_properties_plugin.h"
#include "nl_footprint_properties_plugin_impl.h"
#include <advanced_config.h>
#include <kiplatform/drivers.h>
NL_FOOTPRINT_PROPERTIES_PLUGIN::NL_FOOTPRINT_PROPERTIES_PLUGIN( EDA_3D_CANVAS* aViewport )
{
if( ADVANCED_CFG::GetCfg().m_Use3DConnexionDriver
&& KIPLATFORM::DRIVERS::Valid3DConnexionDriverVersion() )
{
m_impl = std::make_unique<NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL>( aViewport );
m_impl->Connect();
}
}
NL_FOOTPRINT_PROPERTIES_PLUGIN::~NL_FOOTPRINT_PROPERTIES_PLUGIN() = default;
void NL_FOOTPRINT_PROPERTIES_PLUGIN::SetFocus( bool focus )
{
if( m_impl )
m_impl->SetFocus( focus );
}
@@ -1,62 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2024 3Dconnexion
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file nl_footprint_properties_plugin.h
* @brief declaration of the nl_footprint_properties_plugin class
*/
#ifndef NL_FOOTPRINT_PROPERTIES_PLUGIN_H_
#define NL_FOOTPRINT_PROPERTIES_PLUGIN_H_
#include <memory>
// Forward declarations.
class EDA_3D_CANVAS;
class NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL;
/**
* The class that implements the public interface to the SpaceMouse plug-in.
*/
class NL_FOOTPRINT_PROPERTIES_PLUGIN
{
public:
/**
* Initializes a new instance of the NL_FOOTPRINT_PROPERTIES_PLUGIN.
*
* @param aViewport is the viewport to be navigated.
*/
NL_FOOTPRINT_PROPERTIES_PLUGIN( EDA_3D_CANVAS* aViewport );
virtual ~NL_FOOTPRINT_PROPERTIES_PLUGIN();
/**
* Set the connection to the 3Dconnexion driver to the focus state so that
* 3DMouse data is routed here.
*
* @param aFocus is true to set the connection active.
*/
void SetFocus( bool aFocus = true );
private:
std::unique_ptr<NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL> m_impl;
};
#endif // NL_FOOTPRINT_PROPERTIES_PLUGIN_H_
@@ -1,162 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2024 3Dconnexion
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nl_footprint_properties_plugin_impl.h"
#include <3d-viewer/3d_canvas/eda_3d_canvas.h>
// KiCAD includes
#include <tool/action_manager.h>
#include <tool/tool_manager.h>
#include <tool/tools_holder.h>
#include <wx/mstream.h>
#define BOUNDING_BOX_SCALE_FACTOR 1.3f
/**
* Flag to enable the NL_FOOTPRINT_PROPERTIES_PLUGIN debug tracing.
*
* Use "KI_TRACE_NL_FOOTPRINT_PROPERTIES_PLUGIN" to enable.
*
* @ingroup trace_env_vars
*/
const wxChar* NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL::m_logTrace =
wxT( "KI_TRACE_NL_FOOTPRINT_PROPERTIES_PLUGIN" );
NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL::NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL(EDA_3D_CANVAS* aCanvas) :
NL_3D_VIEWER_PLUGIN_IMPL(aCanvas, "KiCAD Footprint Properties")
{}
long NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL::GetModelExtents( navlib::box_t& extents ) const
{
SFVEC3F min = NL_3D_VIEWER_PLUGIN_IMPL::GetCanvas()->GetBoardAdapter().GetBBox().Min();
SFVEC3F max = NL_3D_VIEWER_PLUGIN_IMPL::GetCanvas()->GetBoardAdapter().GetBBox().Max();
SFVEC3F diff = ( BOUNDING_BOX_SCALE_FACTOR - 1.f ) / 2.f * ( max - min );
min -= diff;
max += diff;
extents = { min.x, min.y, min.z, max.x, max.y, max.z };
return 0;
}
void NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL::exportCommandsAndImages()
{
std::list<TOOL_ACTION*> actions = ACTION_MANAGER::GetActionList();
if( actions.size() == 0 )
{
return;
}
using TDx::SpaceMouse::CCommand;
using TDx::SpaceMouse::CCommandSet;
// The root action set node
CCommandSet commandSet( "EDA_3D_CANVAS", "3D Viewer" );
// Activate the command set
NAV_3D::PutActiveCommands( commandSet.GetId() );
// temporary store for the categories
CATEGORY_STORE categoryStore;
std::vector<TDx::CImage> vImages;
// add the action set to the category_store
categoryStore.insert( categoryStore.end(), CATEGORY_STORE::value_type( ".", &commandSet ) );
std::list<TOOL_ACTION*>::const_iterator it;
for( it = actions.begin(); it != actions.end(); ++it )
{
const TOOL_ACTION* action = *it;
std::string label = action->GetMenuLabel().ToStdString();
if( label.empty() )
{
continue;
}
std::string name = action->GetName();
// Do no export commands for the pcbnew app.
if( name.rfind( "pcbnew.", 0 ) == 0 )
{
continue;
}
// Exclude commands which can't be used in the footprint properties.
if( name.rfind( "3DViewer.Control.pivotCenter", 0 ) == 0
|| name.rfind( "3DViewer.Control.material", 0 ) == 0
|| name.rfind( "3DViewer.Control.attribute", 0 ) == 0
|| name.rfind( "3DViewer.Control.show", 0 ) == 0 )
{
continue;
}
std::string strCategory = action->GetToolName();
CATEGORY_STORE::iterator iter = categoryStore.find( strCategory );
if( iter == categoryStore.end() )
{
iter = add_category( std::move( strCategory ), categoryStore );
}
std::string description = action->GetDescription().ToStdString();
// Arbitrary 8-bit data stream
wxMemoryOutputStream imageStream;
if( action->GetIcon() != BITMAPS::INVALID_BITMAP )
{
wxImage image = KiBitmap( action->GetIcon() ).ConvertToImage();
image.SaveFile( imageStream, wxBitmapType::wxBITMAP_TYPE_PNG );
image.Destroy();
if( imageStream.GetSize() )
{
wxStreamBuffer* streamBuffer = imageStream.GetOutputStreamBuffer();
TDx::CImage tdxImage = TDx::CImage::FromData( "", 0, name.c_str() );
tdxImage.AssignImage( std::string( reinterpret_cast<const char*>(
streamBuffer->GetBufferStart() ),
streamBuffer->GetBufferSize() ),
0 );
wxLogTrace( m_logTrace, wxT( "Adding image for : %s" ), name );
vImages.push_back( std::move( tdxImage ) );
}
}
wxLogTrace( m_logTrace, wxT( "Inserting command: %s, description: %s, in category: %s" ),
name, description, iter->first );
iter->second->push_back(
CCommand( std::move( name ), std::move( label ), std::move( description ) ) );
}
NAV_3D::AddCommandSet( commandSet );
NAV_3D::AddImages( vImages );
}
@@ -1,69 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2024 3Dconnexion
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file nl_footprint_properties_plugin_impl.h
* @brief declaration of the nl_footprint_properties_plugin_impl class
*/
#ifndef NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL_H_
#define NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL_H_
#include "nl_3d_viewer_plugin_impl.h"
// TDxWare SDK.
#include <SpaceMouse/CNavigation3D.hpp>
/**
* The class that adjusts NL_3D_VIEWER_PLUGIN_IMPL implementation for 3D Model preview in
* footprint properties dialog.
*/
class NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL : public NL_3D_VIEWER_PLUGIN_IMPL
{
public:
/**
* Initialize a new instance of the NL_FOOTPRINT_PROPERTIES_PLUGIN.
*
* @param aCanvas is the viewport to be navigated.
*/
NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL( EDA_3D_CANVAS* aCanvas );
private:
/**
* Get Footprint 3D Model extents.
*
* @param extents is the box around the 3D model.
*/
long GetModelExtents( navlib::box_t& extents ) const override;
/**
* Export the invocable actions and images to the 3Dconnexion UI.
*/
void exportCommandsAndImages() override;
private:
/**
* Trace mask used to enable or disable the trace output of this class.
* The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_NL_FOOTPRINT_PROPERTIES_PLUGIN". See the wxWidgets documentation on
* wxLogTrace for more information.
*/
static const wxChar* m_logTrace;
};
#endif // NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL_H_
+1
View File
@@ -0,0 +1 @@
#define PLUGINDIR "@CMAKE_INSTALL_FULL_LIBDIR@"
@@ -0,0 +1,961 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file c3d_render_createscene_ogl_legacy.cpp
* @brief
*/
#include "c3d_render_ogl_legacy.h"
#include "ogl_legacy_utils.h"
#include <class_board.h>
#include <class_module.h>
#include "../../3d_math.h"
#include "../../3d_fastmath.h"
#include <trigo.h>
#include <project.h>
#include <profile.h> // To use GetRunningMicroSecs or another profiling utility
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CFILLEDCIRCLE2D * aFilledCircle,
CLAYER_TRIANGLES *aDstLayer,
float aZtop,
float aZbot )
{
const SFVEC2F &center = aFilledCircle->GetCenter();
const float radius = aFilledCircle->GetRadius() *
2.0f; // Double because the render triangle
// This is a small adjustment to the circle texture
const float texture_factor = (8.0f / (float)SIZE_OF_CIRCLE_TEXTURE) + 1.0f;
const float f = (sqrtf(2.0f) / 2.0f) * radius * texture_factor;
// Top and Bot segments ends are just triangle semi-circles, so need to add
// it in duplicated
aDstLayer->m_layer_top_segment_ends->AddTriangle( SFVEC3F( center.x + f, center.y, aZtop ),
SFVEC3F( center.x - f, center.y, aZtop ),
SFVEC3F( center.x,
center.y - f, aZtop ) );
aDstLayer->m_layer_top_segment_ends->AddTriangle( SFVEC3F( center.x - f, center.y, aZtop ),
SFVEC3F( center.x + f, center.y, aZtop ),
SFVEC3F( center.x,
center.y + f, aZtop ) );
aDstLayer->m_layer_bot_segment_ends->AddTriangle( SFVEC3F( center.x - f, center.y, aZbot ),
SFVEC3F( center.x + f, center.y, aZbot ),
SFVEC3F( center.x,
center.y - f, aZbot ) );
aDstLayer->m_layer_bot_segment_ends->AddTriangle( SFVEC3F( center.x + f, center.y, aZbot ),
SFVEC3F( center.x - f, center.y, aZbot ),
SFVEC3F( center.x,
center.y + f, aZbot ) );
}
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CPOLYGON4PTS2D * aPoly,
CLAYER_TRIANGLES *aDstLayer,
float aZtop,
float aZbot )
{
const SFVEC2F &v0 = aPoly->GetV0();
const SFVEC2F &v1 = aPoly->GetV1();
const SFVEC2F &v2 = aPoly->GetV2();
const SFVEC2F &v3 = aPoly->GetV3();
add_triangle_top_bot( aDstLayer, v0, v2, v1, aZtop, aZbot );
add_triangle_top_bot( aDstLayer, v2, v0, v3, aZtop, aZbot );
}
void C3D_RENDER_OGL_LEGACY::generate_ring_contour( const SFVEC2F &aCenter,
float aInnerRadius,
float aOuterRadius,
unsigned int aNr_sides_per_circle,
std::vector< SFVEC2F > &aInnerContourResult,
std::vector< SFVEC2F > &aOuterContourResult,
bool aInvertOrder )
{
aInnerContourResult.clear();
aInnerContourResult.reserve( aNr_sides_per_circle + 2 );
aOuterContourResult.clear();
aOuterContourResult.reserve( aNr_sides_per_circle + 2 );
const int delta = 3600 / aNr_sides_per_circle;
for( int ii = 0; ii < 3600; ii += delta )
{
float angle = (float)( aInvertOrder ? ( 3600 - ii ) : ii )
* 2.0f * glm::pi<float>() / 3600.0f;
const SFVEC2F rotatedDir = SFVEC2F( cos( angle ), sin( angle ) );
aInnerContourResult.push_back( SFVEC2F( aCenter.x + rotatedDir.x * aInnerRadius,
aCenter.y + rotatedDir.y * aInnerRadius ) );
aOuterContourResult.push_back( SFVEC2F( aCenter.x + rotatedDir.x * aOuterRadius,
aCenter.y + rotatedDir.y * aOuterRadius ) );
}
aInnerContourResult.push_back( aInnerContourResult[0] );
aOuterContourResult.push_back( aOuterContourResult[0] );
wxASSERT( aInnerContourResult.size() == aOuterContourResult.size() );
}
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CRING2D * aRing,
CLAYER_TRIANGLES *aDstLayer,
float aZtop,
float aZbot )
{
const SFVEC2F &center = aRing->GetCenter();
const float inner = aRing->GetInnerRadius();
const float outer = aRing->GetOuterRadius();
std::vector< SFVEC2F > innerContour;
std::vector< SFVEC2F > outerContour;
generate_ring_contour( center,
inner,
outer,
m_settings.GetNrSegmentsCircle( outer * 2.0f ),
innerContour,
outerContour,
false );
// This will add the top and bot quads that will form the approximated ring
for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
{
const SFVEC2F &vi0 = innerContour[i + 0];
const SFVEC2F &vi1 = innerContour[i + 1];
const SFVEC2F &vo0 = outerContour[i + 0];
const SFVEC2F &vo1 = outerContour[i + 1];
aDstLayer->m_layer_top_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZtop ),
SFVEC3F( vi0.x, vi0.y, aZtop ),
SFVEC3F( vo0.x, vo0.y, aZtop ),
SFVEC3F( vo1.x, vo1.y, aZtop ) );
aDstLayer->m_layer_bot_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZbot ),
SFVEC3F( vo1.x, vo1.y, aZbot ),
SFVEC3F( vo0.x, vo0.y, aZbot ),
SFVEC3F( vi0.x, vi0.y, aZbot ) );
}
}
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CTRIANGLE2D * aTri,
CLAYER_TRIANGLES *aDstLayer,
float aZtop,
float aZbot )
{
const SFVEC2F &v1 = aTri->GetP1();
const SFVEC2F &v2 = aTri->GetP2();
const SFVEC2F &v3 = aTri->GetP3();
add_triangle_top_bot( aDstLayer, v1, v2, v3, aZtop, aZbot );
}
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CROUNDSEGMENT2D * aSeg,
CLAYER_TRIANGLES *aDstLayer,
float aZtop,
float aZbot )
{
const SFVEC2F leftStart = aSeg->GetLeftStar();
const SFVEC2F leftEnd = aSeg->GetLeftEnd();
const SFVEC2F leftDir = aSeg->GetLeftDir();
const SFVEC2F rightStart = aSeg->GetRightStar();
const SFVEC2F rightEnd = aSeg->GetRightEnd();
const SFVEC2F rightDir = aSeg->GetRightDir();
const float radius = aSeg->GetRadius();
const SFVEC2F start = aSeg->GetStart();
const SFVEC2F end = aSeg->GetEnd();
const float texture_factor = (12.0f / (float)SIZE_OF_CIRCLE_TEXTURE) + 1.0f;
const float texture_factorF= ( 6.0f / (float)SIZE_OF_CIRCLE_TEXTURE) + 1.0f;
const float radius_of_the_square = sqrtf( aSeg->GetRadiusSquared() * 2.0f );
const float radius_triangle_factor = (radius_of_the_square - radius) / radius;
const SFVEC2F factorS = SFVEC2F( -rightDir.y * radius * radius_triangle_factor,
rightDir.x * radius * radius_triangle_factor );
const SFVEC2F factorE = SFVEC2F( -leftDir.y * radius * radius_triangle_factor,
leftDir.x * radius * radius_triangle_factor );
// Top end segment triangles (semi-circles)
aDstLayer->m_layer_top_segment_ends->AddTriangle(
SFVEC3F( rightEnd.x + texture_factor * factorS.x,
rightEnd.y + texture_factor * factorS.y,
aZtop ),
SFVEC3F( leftStart.x + texture_factor * factorE.x,
leftStart.y + texture_factor * factorE.y,
aZtop ),
SFVEC3F( start.x - texture_factorF * leftDir.x * radius * sqrtf( 2.0f ),
start.y - texture_factorF * leftDir.y * radius * sqrtf( 2.0f ),
aZtop ) );
aDstLayer->m_layer_top_segment_ends->AddTriangle(
SFVEC3F( leftEnd.x + texture_factor * factorE.x,
leftEnd.y + texture_factor * factorE.y, aZtop ),
SFVEC3F( rightStart.x + texture_factor * factorS.x,
rightStart.y + texture_factor * factorS.y, aZtop ),
SFVEC3F( end.x - texture_factorF * rightDir.x * radius * sqrtf( 2.0f ),
end.y - texture_factorF * rightDir.y * radius * sqrtf( 2.0f ),
aZtop ) );
// Bot end segment triangles (semi-circles)
aDstLayer->m_layer_bot_segment_ends->AddTriangle(
SFVEC3F( leftStart.x + texture_factor * factorE.x,
leftStart.y + texture_factor * factorE.y,
aZbot ),
SFVEC3F( rightEnd.x + texture_factor * factorS.x,
rightEnd.y + texture_factor * factorS.y,
aZbot ),
SFVEC3F( start.x - texture_factorF * leftDir.x * radius * sqrtf( 2.0f ),
start.y - texture_factorF * leftDir.y * radius * sqrtf( 2.0f ),
aZbot ) );
aDstLayer->m_layer_bot_segment_ends->AddTriangle(
SFVEC3F( rightStart.x + texture_factor * factorS.x,
rightStart.y + texture_factor * factorS.y, aZbot ),
SFVEC3F( leftEnd.x + texture_factor * factorE.x,
leftEnd.y + texture_factor * factorE.y, aZbot ),
SFVEC3F( end.x - texture_factorF * rightDir.x * radius * sqrtf( 2.0f ),
end.y - texture_factorF * rightDir.y * radius * sqrtf( 2.0f ),
aZbot ) );
// Segment top and bot planes
aDstLayer->m_layer_top_triangles->AddQuad(
SFVEC3F( rightEnd.x, rightEnd.y, aZtop ),
SFVEC3F( rightStart.x, rightStart.y, aZtop ),
SFVEC3F( leftEnd.x, leftEnd.y, aZtop ),
SFVEC3F( leftStart.x, leftStart.y, aZtop ) );
aDstLayer->m_layer_bot_triangles->AddQuad(
SFVEC3F( rightEnd.x, rightEnd.y, aZbot ),
SFVEC3F( leftStart.x, leftStart.y, aZbot ),
SFVEC3F( leftEnd.x, leftEnd.y, aZbot ),
SFVEC3F( rightStart.x, rightStart.y, aZbot ) );
}
CLAYERS_OGL_DISP_LISTS *C3D_RENDER_OGL_LEGACY::generate_holes_display_list(
const LIST_OBJECT2D &aListHolesObject2d,
const SHAPE_POLY_SET &aPoly,
float aZtop,
float aZbot,
bool aInvertFaces )
{
CLAYERS_OGL_DISP_LISTS *ret = NULL;
if( aListHolesObject2d.size() > 0 )
{
CLAYER_TRIANGLES *layerTriangles = new CLAYER_TRIANGLES( aListHolesObject2d.size() * 2 );
// Convert the list of objects(filled circles) to triangle layer structure
for( LIST_OBJECT2D::const_iterator itemOnLayer = aListHolesObject2d.begin();
itemOnLayer != aListHolesObject2d.end();
++itemOnLayer )
{
const COBJECT2D *object2d_A = static_cast<const COBJECT2D *>(*itemOnLayer);
wxASSERT( (object2d_A->GetObjectType() == OBJ2D_FILLED_CIRCLE) ||
(object2d_A->GetObjectType() == OBJ2D_ROUNDSEG) );
switch( object2d_A->GetObjectType() )
{
case OBJ2D_FILLED_CIRCLE:
add_object_to_triangle_layer( (const CFILLEDCIRCLE2D *)object2d_A,
layerTriangles,
aZtop, aZbot );
break;
case OBJ2D_ROUNDSEG:
add_object_to_triangle_layer( (const CROUNDSEGMENT2D *) object2d_A,
layerTriangles,
aZtop, aZbot );
break;
default:
wxFAIL_MSG("C3D_RENDER_OGL_LEGACY::generate_holes_display_list: Object type is not implemented");
break;
}
}
// Note: he can have a aListHolesObject2d whith holes but without countours
// eg: when there are only NPTH on the list and the contours were not
// added
if( aPoly.OutlineCount() > 0 )
{
layerTriangles->AddToMiddleContourns( aPoly,
aZbot,
aZtop,
m_settings.BiuTo3Dunits(),
aInvertFaces );
}
ret = new CLAYERS_OGL_DISP_LISTS( *layerTriangles,
m_ogl_circle_texture,
aZbot,
aZtop );
delete layerTriangles;
}
return ret;
}
void C3D_RENDER_OGL_LEGACY::reload( REPORTER *aStatusTextReporter )
{
m_reloadRequested = false;
ogl_free_all_display_lists();
COBJECT2D_STATS::Instance().ResetStats();
#ifdef PRINT_STATISTICS_3D_VIEWER
printf("InitSettings...\n");
#endif
unsigned stats_startReloadTime = GetRunningMicroSecs();
m_settings.InitSettings( aStatusTextReporter );
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_endReloadTime = GetRunningMicroSecs();
#endif
SFVEC3F camera_pos = m_settings.GetBoardCenter3DU();
m_settings.CameraGet().SetBoardLookAtPos( camera_pos );
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_start_OpenGL_Load_Time = GetRunningMicroSecs();
#endif
if( aStatusTextReporter )
aStatusTextReporter->Report( _( "Load OpenGL: board" ) );
// Create Board
// /////////////////////////////////////////////////////////////////////////
CCONTAINER2D boardContainer;
SHAPE_POLY_SET tmpBoard = m_settings.GetBoardPoly();
Convert_shape_line_polygon_to_triangles( tmpBoard,
boardContainer,
m_settings.BiuTo3Dunits(),
(const BOARD_ITEM &)*m_settings.GetBoard() );
const LIST_OBJECT2D &listBoardObject2d = boardContainer.GetList();
if( listBoardObject2d.size() > 0 )
{
// We will set a unitary Z so it will in future used with transformations
// since the board poly will be used not only to draw itself but also the
// solder mask layers.
const float layer_z_top = 1.0f;
const float layer_z_bot = 0.0f;
CLAYER_TRIANGLES *layerTriangles = new CLAYER_TRIANGLES( listBoardObject2d.size() );
// Convert the list of objects(triangles) to triangle layer structure
for( LIST_OBJECT2D::const_iterator itemOnLayer = listBoardObject2d.begin();
itemOnLayer != listBoardObject2d.end();
++itemOnLayer )
{
const COBJECT2D *object2d_A = static_cast<const COBJECT2D *>(*itemOnLayer);
wxASSERT( object2d_A->GetObjectType() == OBJ2D_TRIANGLE );
const CTRIANGLE2D *tri = (const CTRIANGLE2D *)object2d_A;
const SFVEC2F &v1 = tri->GetP1();
const SFVEC2F &v2 = tri->GetP2();
const SFVEC2F &v3 = tri->GetP3();
add_triangle_top_bot( layerTriangles,
v1,
v2,
v3,
layer_z_top,
layer_z_bot );
}
const SHAPE_POLY_SET &boardPoly = m_settings.GetBoardPoly();
wxASSERT( boardPoly.OutlineCount() > 0 );
if( boardPoly.OutlineCount() > 0 )
{
layerTriangles->AddToMiddleContourns( boardPoly,
layer_z_bot,
layer_z_top,
m_settings.BiuTo3Dunits(),
false );
m_ogl_disp_list_board = new CLAYERS_OGL_DISP_LISTS( *layerTriangles,
m_ogl_circle_texture,
layer_z_top,
layer_z_top );
}
delete layerTriangles;
}
// Create Through Holes and vias
// /////////////////////////////////////////////////////////////////////////
if( aStatusTextReporter )
aStatusTextReporter->Report( _( "Load OpenGL: holes and vias" ) );
m_ogl_disp_list_through_holes_outer = generate_holes_display_list(
m_settings.GetThroughHole_Outer().GetList(),
m_settings.GetThroughHole_Outer_poly(),
1.0f,
0.0f,
false );
SHAPE_POLY_SET bodyHoles = m_settings.GetThroughHole_Outer_poly();
bodyHoles.BooleanAdd( m_settings.GetThroughHole_Outer_poly_NPTH(),
SHAPE_POLY_SET::PM_FAST );
m_ogl_disp_list_through_holes_outer_with_npth = generate_holes_display_list(
m_settings.GetThroughHole_Outer().GetList(),
bodyHoles,
1.0f,
0.0f,
false );
m_ogl_disp_list_through_holes_inner = generate_holes_display_list(
m_settings.GetThroughHole_Inner().GetList(),
m_settings.GetThroughHole_Inner_poly(),
1.0f,
0.0f,
true );
m_ogl_disp_list_through_holes_vias_outer = generate_holes_display_list(
m_settings.GetThroughHole_Vias_Outer().GetList(),
m_settings.GetThroughHole_Vias_Outer_poly(),
1.0f,
0.0f,
false );
// Not in use
//m_ogl_disp_list_through_holes_vias_inner = generate_holes_display_list(
// m_settings.GetThroughHole_Vias_Inner().GetList(),
// m_settings.GetThroughHole_Vias_Inner_poly(),
// 1.0f, 0.0f,
// false );
const MAP_POLY & innerMapHoles = m_settings.GetPolyMapHoles_Inner();
const MAP_POLY & outerMapHoles = m_settings.GetPolyMapHoles_Outer();
wxASSERT( innerMapHoles.size() == outerMapHoles.size() );
const MAP_CONTAINER_2D &map_holes = m_settings.GetMapLayersHoles();
if( outerMapHoles.size() > 0 )
{
float layer_z_bot = 0.0f;
float layer_z_top = 0.0f;
for( MAP_POLY::const_iterator ii = outerMapHoles.begin();
ii != outerMapHoles.end();
++ii )
{
PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
const SHAPE_POLY_SET *poly = static_cast<const SHAPE_POLY_SET *>(ii->second);
const CBVHCONTAINER2D *container = map_holes.at( layer_id );
get_layer_z_pos( layer_id, layer_z_top, layer_z_bot );
m_ogl_disp_lists_layers_holes_outer[layer_id] = generate_holes_display_list(
container->GetList(), *poly, layer_z_top, layer_z_bot, false );
}
for( MAP_POLY::const_iterator ii = innerMapHoles.begin();
ii != innerMapHoles.end();
++ii )
{
PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
const SHAPE_POLY_SET *poly = static_cast<const SHAPE_POLY_SET *>(ii->second);
const CBVHCONTAINER2D *container = map_holes.at( layer_id );
get_layer_z_pos( layer_id, layer_z_top, layer_z_bot );
m_ogl_disp_lists_layers_holes_inner[layer_id] = generate_holes_display_list(
container->GetList(), *poly, layer_z_top, layer_z_bot, false );
}
}
// Generate vertical cylinders of vias and pads (copper)
generate_3D_Vias_and_Pads();
// Add layers maps
if( aStatusTextReporter )
aStatusTextReporter->Report( _( "Load OpenGL: layers" ) );
for( MAP_CONTAINER_2D::const_iterator ii = m_settings.GetMapLayers().begin();
ii != m_settings.GetMapLayers().end();
++ii )
{
PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
if( !m_settings.Is3DLayerEnabled( layer_id ) )
continue;
const CBVHCONTAINER2D *container2d = static_cast<const CBVHCONTAINER2D *>(ii->second);
const LIST_OBJECT2D &listObject2d = container2d->GetList();
if( listObject2d.size() == 0 )
continue;
float layer_z_bot = 0.0f;
float layer_z_top = 0.0f;
get_layer_z_pos( layer_id, layer_z_top, layer_z_bot );
// Calculate an estimation for the nr of triangles based on the nr of objects
unsigned int nrTrianglesEstimation = listObject2d.size() * 8;
CLAYER_TRIANGLES *layerTriangles = new CLAYER_TRIANGLES( nrTrianglesEstimation );
m_triangles[layer_id] = layerTriangles;
// Load the 2D (X,Y axis) component of shapes
for( LIST_OBJECT2D::const_iterator itemOnLayer = listObject2d.begin();
itemOnLayer != listObject2d.end();
++itemOnLayer )
{
const COBJECT2D *object2d_A = static_cast<const COBJECT2D *>(*itemOnLayer);
switch( object2d_A->GetObjectType() )
{
case OBJ2D_FILLED_CIRCLE:
add_object_to_triangle_layer( (const CFILLEDCIRCLE2D *)object2d_A,
layerTriangles, layer_z_top, layer_z_bot );
break;
case OBJ2D_POLYGON4PT:
add_object_to_triangle_layer( (const CPOLYGON4PTS2D *)object2d_A,
layerTriangles, layer_z_top, layer_z_bot );
break;
case OBJ2D_RING:
add_object_to_triangle_layer( (const CRING2D *)object2d_A,
layerTriangles, layer_z_top, layer_z_bot );
break;
case OBJ2D_TRIANGLE:
add_object_to_triangle_layer( (const CTRIANGLE2D *)object2d_A,
layerTriangles, layer_z_top, layer_z_bot );
break;
case OBJ2D_ROUNDSEG:
add_object_to_triangle_layer( (const CROUNDSEGMENT2D *) object2d_A,
layerTriangles, layer_z_top, layer_z_bot );
break;
default:
wxFAIL_MSG("C3D_RENDER_OGL_LEGACY: Object type is not implemented");
break;
}
}
const MAP_POLY &map_poly = m_settings.GetPolyMap();
// Load the vertical (Z axis) component of shapes
if( map_poly.find( layer_id ) != map_poly.end() )
{
const SHAPE_POLY_SET *polyList = map_poly.at( layer_id );
if( polyList->OutlineCount() > 0 )
layerTriangles->AddToMiddleContourns( *polyList, layer_z_bot, layer_z_top,
m_settings.BiuTo3Dunits(), false );
}
// Create display list
// /////////////////////////////////////////////////////////////////////
m_ogl_disp_lists_layers[layer_id] = new CLAYERS_OGL_DISP_LISTS( *layerTriangles,
m_ogl_circle_texture,
layer_z_bot,
layer_z_top );
}// for each layer on map
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_end_OpenGL_Load_Time = GetRunningMicroSecs();
#endif
// Load 3D models
// /////////////////////////////////////////////////////////////////////////
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_start_models_Load_Time = GetRunningMicroSecs();
#endif
if( aStatusTextReporter )
aStatusTextReporter->Report( _( "Loading 3D models" ) );
load_3D_models( aStatusTextReporter );
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_end_models_Load_Time = GetRunningMicroSecs();
printf( "C3D_RENDER_OGL_LEGACY::reload times:\n" );
printf( " Reload board: %.3f ms\n",
(float)( stats_endReloadTime - stats_startReloadTime ) / 1000.0f );
printf( " Loading to openGL: %.3f ms\n",
(float)( stats_end_OpenGL_Load_Time - stats_start_OpenGL_Load_Time ) / 1000.0f );
printf( " Loading 3D models: %.3f ms\n",
(float)( stats_end_models_Load_Time - stats_start_models_Load_Time ) / 1000.0f );
COBJECT2D_STATS::Instance().PrintStats();
#endif
if( aStatusTextReporter )
{
// Calculation time in seconds
const double calculation_time = (double)( GetRunningMicroSecs() -
stats_startReloadTime) / 1e6;
aStatusTextReporter->Report( wxString::Format( _( "Reload time %.3f s" ),
calculation_time ) );
}
}
void C3D_RENDER_OGL_LEGACY::add_triangle_top_bot( CLAYER_TRIANGLES *aDst,
const SFVEC2F &v0,
const SFVEC2F &v1,
const SFVEC2F &v2,
float top,
float bot )
{
aDst->m_layer_bot_triangles->AddTriangle( SFVEC3F( v0.x, v0.y, bot ),
SFVEC3F( v1.x, v1.y, bot ),
SFVEC3F( v2.x, v2.y, bot ) );
aDst->m_layer_top_triangles->AddTriangle( SFVEC3F( v2.x, v2.y, top ),
SFVEC3F( v1.x, v1.y, top ),
SFVEC3F( v0.x, v0.y, top ) );
}
void C3D_RENDER_OGL_LEGACY::get_layer_z_pos ( PCB_LAYER_ID aLayerID,
float &aOutZtop,
float &aOutZbot ) const
{
aOutZbot = m_settings.GetLayerBottomZpos3DU( aLayerID );
aOutZtop = m_settings.GetLayerTopZpos3DU( aLayerID );
if( aOutZtop < aOutZbot )
{
float tmpFloat = aOutZbot;
aOutZbot = aOutZtop;
aOutZtop = tmpFloat;
}
}
void C3D_RENDER_OGL_LEGACY::generate_cylinder( const SFVEC2F &aCenter,
float aInnerRadius,
float aOuterRadius,
float aZtop,
float aZbot,
unsigned int aNr_sides_per_circle,
CLAYER_TRIANGLES *aDstLayer )
{
std::vector< SFVEC2F > innerContour;
std::vector< SFVEC2F > outerContour;
generate_ring_contour( aCenter,
aInnerRadius,
aOuterRadius,
aNr_sides_per_circle,
innerContour,
outerContour,
false );
for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
{
const SFVEC2F &vi0 = innerContour[i + 0];
const SFVEC2F &vi1 = innerContour[i + 1];
const SFVEC2F &vo0 = outerContour[i + 0];
const SFVEC2F &vo1 = outerContour[i + 1];
aDstLayer->m_layer_top_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZtop ),
SFVEC3F( vi0.x, vi0.y, aZtop ),
SFVEC3F( vo0.x, vo0.y, aZtop ),
SFVEC3F( vo1.x, vo1.y, aZtop ) );
aDstLayer->m_layer_bot_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZbot ),
SFVEC3F( vo1.x, vo1.y, aZbot ),
SFVEC3F( vo0.x, vo0.y, aZbot ),
SFVEC3F( vi0.x, vi0.y, aZbot ) );
}
aDstLayer->AddToMiddleContourns( outerContour, aZbot, aZtop, true );
aDstLayer->AddToMiddleContourns( innerContour, aZbot, aZtop, false );
}
void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
{
if( m_settings.GetStats_Nr_Vias() )
{
const unsigned int reserve_nr_triangles_estimation =
m_settings.GetNrSegmentsCircle( m_settings.GetStats_Med_Via_Hole_Diameter3DU() ) *
8 *
m_settings.GetStats_Nr_Vias();
CLAYER_TRIANGLES *layerTriangleVIA = new CLAYER_TRIANGLES( reserve_nr_triangles_estimation );
// Insert plated vertical holes inside the board
// /////////////////////////////////////////////////////////////////////////
// Insert vias holes (vertical cylinders)
for( const TRACK* track = m_settings.GetBoard()->m_Track;
track;
track = track->Next() )
{
if( track->Type() == PCB_VIA_T )
{
const VIA *via = static_cast<const VIA*>(track);
const float holediameter = via->GetDrillValue() * m_settings.BiuTo3Dunits();
const float thickness = m_settings.GetCopperThickness3DU();
const int nrSegments = m_settings.GetNrSegmentsCircle( via->GetDrillValue() );
const double correctionFactor = m_settings.GetCircleCorrectionFactor( nrSegments );
const float hole_inner_radius = ( holediameter / 2.0f ) * correctionFactor;
const SFVEC2F via_center( via->GetStart().x * m_settings.BiuTo3Dunits(),
-via->GetStart().y * m_settings.BiuTo3Dunits() );
PCB_LAYER_ID top_layer, bottom_layer;
via->LayerPair( &top_layer, &bottom_layer );
float ztop, zbot, dummy;
get_layer_z_pos( top_layer, ztop, dummy );
get_layer_z_pos( bottom_layer, dummy, zbot );
wxASSERT( zbot < ztop );
generate_cylinder( via_center,
hole_inner_radius,
hole_inner_radius + thickness,
ztop,
zbot,
nrSegments,
layerTriangleVIA );
}
}
m_ogl_disp_list_via = new CLAYERS_OGL_DISP_LISTS( *layerTriangleVIA,
0,
0.0f,
0.0f );
delete layerTriangleVIA;
}
if( m_settings.GetStats_Nr_Holes() > 0 )
{
SHAPE_POLY_SET tht_outer_holes_poly; // Stores the outer poly of the copper holes (the pad)
SHAPE_POLY_SET tht_inner_holes_poly; // Stores the inner poly of the copper holes (the hole)
tht_outer_holes_poly.RemoveAllContours();
tht_inner_holes_poly.RemoveAllContours();
// Insert pads holes (vertical cylinders)
for( const MODULE* module = m_settings.GetBoard()->m_Modules;
module;
module = module->Next() )
{
for( const D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
{
if( pad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED )
{
const wxSize drillsize = pad->GetDrillSize();
const bool hasHole = drillsize.x && drillsize.y;
if( !hasHole )
continue;
// we use the hole diameter to calculate the seg count.
// for round holes, drillsize.x == drillsize.y
// for slots, the diameter is the smaller of (drillsize.x, drillsize.y)
int copperThickness = m_settings.GetCopperThicknessBIU();
int radius = std::min( drillsize.x, drillsize.y ) / 2 + copperThickness;
int nrSegments = m_settings.GetNrSegmentsCircle( radius * 2 );
double correctionFactor = m_settings.GetCircleCorrectionFactor( nrSegments );
int correction = radius * ( correctionFactor - 1 );
pad->BuildPadDrillShapePolygon( tht_outer_holes_poly,
copperThickness + correction,
nrSegments );
pad->BuildPadDrillShapePolygon( tht_inner_holes_poly,
correction,
nrSegments );
}
}
}
// Subtract the holes
tht_outer_holes_poly.BooleanSubtract( tht_inner_holes_poly, SHAPE_POLY_SET::PM_FAST );
CCONTAINER2D holesContainer;
Convert_shape_line_polygon_to_triangles( tht_outer_holes_poly,
holesContainer,
m_settings.BiuTo3Dunits(),
(const BOARD_ITEM &)*m_settings.GetBoard() );
const LIST_OBJECT2D &listHolesObject2d = holesContainer.GetList();
if( listHolesObject2d.size() > 0 )
{
float layer_z_top, layer_z_bot, dummy;
get_layer_z_pos( F_Cu, layer_z_top, dummy );
get_layer_z_pos( B_Cu, dummy, layer_z_bot );
CLAYER_TRIANGLES *layerTriangles = new CLAYER_TRIANGLES( listHolesObject2d.size() );
// Convert the list of objects(triangles) to triangle layer structure
for( LIST_OBJECT2D::const_iterator itemOnLayer = listHolesObject2d.begin();
itemOnLayer != listHolesObject2d.end();
++itemOnLayer )
{
const COBJECT2D *object2d_A = static_cast<const COBJECT2D *>(*itemOnLayer);
wxASSERT( object2d_A->GetObjectType() == OBJ2D_TRIANGLE );
const CTRIANGLE2D *tri = (const CTRIANGLE2D *)object2d_A;
const SFVEC2F &v1 = tri->GetP1();
const SFVEC2F &v2 = tri->GetP2();
const SFVEC2F &v3 = tri->GetP3();
add_triangle_top_bot( layerTriangles, v1, v2, v3,
layer_z_top, layer_z_bot );
}
wxASSERT( tht_outer_holes_poly.OutlineCount() > 0 );
if( tht_outer_holes_poly.OutlineCount() > 0 )
{
layerTriangles->AddToMiddleContourns( tht_outer_holes_poly,
layer_z_bot, layer_z_top,
m_settings.BiuTo3Dunits(),
false );
m_ogl_disp_list_pads_holes = new CLAYERS_OGL_DISP_LISTS(
*layerTriangles,
m_ogl_circle_texture, // not need
layer_z_top, layer_z_top );
}
delete layerTriangles;
}
}
}
/*
* This function will get models from the cache and load it to openGL lists
* in the form of C_OGL_3DMODEL. So this map of models will work as a local
* cache for this render. (cache based on C_OGL_3DMODEL with associated
* openGL lists in GPU memory)
*/
void C3D_RENDER_OGL_LEGACY::load_3D_models( REPORTER *aStatusTextReporter )
{
if( (!m_settings.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL )) &&
(!m_settings.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT )) &&
(!m_settings.GetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL )) )
return;
// Go for all modules
for( const MODULE* module = m_settings.GetBoard()->m_Modules;
module; module = module->Next() )
{
if( !module->Models().empty() )
{
// Get the list of model files for this model
auto sM = module->Models().begin();
auto eM = module->Models().end();
while( sM != eM )
{
if( !sM->m_Filename.empty() )
{
if( aStatusTextReporter )
{
// Display the short filename of the 3D model loaded:
// (the full name is usually too long to be displayed)
wxFileName fn( sM->m_Filename );
wxString msg;
msg.Printf( _( "Loading %s" ), fn.GetFullName() );
aStatusTextReporter->Report( msg );
}
// Check if the model is not present in our cache map
// (Not already loaded in memory)
if( m_3dmodel_map.find( sM->m_Filename ) == m_3dmodel_map.end() )
{
// It is not present, try get it from cache
const S3DMODEL *modelPtr =
m_settings.Get3DCacheManager()->GetModel( sM->m_Filename );
// only add it if the return is not NULL
if( modelPtr )
{
C_OGL_3DMODEL* ogl_model =
new C_OGL_3DMODEL( *modelPtr,
m_settings.MaterialModeGet() );
if( ogl_model )
m_3dmodel_map[ sM->m_Filename ] = ogl_model;
}
}
}
++sM;
}
}
}
}
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More