Commit Graph

655 Commits

Author SHA1 Message Date
Lorenzo Marcantonio 342016b692 Constification of HitTest and GetParent
In particular HitTest for zones *do not* select the nearest vertex/edge as a side effect
2014-05-04 19:08:36 +02:00
Dick Hollenbeck 991926d320 Modular-Kicad milestone B), major portions:
*) Rework the set language support, simplify it by using KIWAY.  Now any major
   frame with a "change language" menu can change the language for all KIWAY_PLAYERs
   in the whole KIWAY.  Multiple KIWAYs are not supported yet.

*) Simplify "modal wxFrame" support, and add that support exclusively to
   KIWAY_PLAYER where it is inherited by all derivatives.  The function
   KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable.

*) Remove the requirements and assumptions that the wxFrame hierarchy always
   had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers
   and editors. This is no longer the case, nor required.

*) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the
   KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame
   quickly.  It also gives control to the KIWAY as to frame hierarchical
   relationships.

*) Change single_top to use the KIWAY for loading a KIFACE and instantiating
   the single KIWAY_PLAYER, see bullet immediately above.

*) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this
   gives the KIFACEs a chance to save their final configuration dope to disk.

*) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and
   these modal frames are distinctly different than their non-modal equivalents.
   KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor,
   so this is another important reason for having a dedicated FRAME_T for each
   modal wxFrame.

On balance, more lines were deleted than were added to achieve all this.
2014-05-03 12:40:19 -05:00
Lorenzo Marcantonio 7b4b3297db - Better way to iterate on vias in the track list (GetFirstVia)
- Converted the Next/Prev C casts to static casts and removed the type
  unsafe ones
- Splitted as virtual the VIA::Flip member instead of using RTTI
- Heavily refactored the 'unconnected track' cleanup routine
- Misc constification
2014-04-30 21:16:22 +02:00
Dick Hollenbeck 0d6560a218 *) Switch kicad.exe to using KIFACE modules for all major top level windows.
Eeschema, Pcbnew, and Cvpcb all run under the same process now,
    FOR THE VERY FIRST TIME!

*)  Added KIWAY::PlayerCreate(), PlayerClose(), and PlayersClose().

*)  Factored FRAME_T into <frame_type.h> from ID_DRAWFRAME_TYPE.

*)  Found that the following command line is helpful for collecting all the *.kiface
    files into the <build>/kicad/ directory so that kicad can find them.

      $ cp `find . -name '*.kiface'` kicad/

    Maybe somebody will want to rework how the CMake files are organized so all
    the binaries can go into the same place.  See python-a-mingw-us.

*)  This might fix the problem on the Mac where child process windows were not
    coming to the front.  See ->Raise() in kicad/mainframe.cpp.

*)  You can set USE_KIFACE to 0 in kicad/mainframe.cpp to chain load child exes
    instead of using the KIFACE modules directly, i.e. revert.
2014-04-19 13:47:20 -05:00
Dick Hollenbeck 5f65d0da93 *) Add KIFACE_I::StartFlags() and IsSingle() so a KIFACE implementation can know
if it is running under single_top.cpp or under a project manager.

*)  Test Kiface().IsSingle() when adding menus, some operations are not permitted
    when running under a project manager and the KIWAY_PLAYER is pegged to a
    specific project.

*)  Implemented KIWAY::KiFACE() so it loads *.kiface files.  They still have to be
    in the same directory as the main *.exe launcher, so this presents some difficulty
    when the binaries are not yet installed but rather the *.kiface files are still
    in their original build directories.  For today, I simply copied _pcbnew.kiface
    to build/kicad/.

*)  Add a test case to kicad/mainframe.cpp just to get an early peek at loading
    _pcbnew.kiface under the C++ project manager.  Got that working for one
    specific invocation just for proof of concept.  Surprise, it works.
2014-04-17 21:05:40 -05:00
jean-pierre charras 229613ef26 Cmakefiles: do not create map file on Windows, because creating map file generates hundred of useless wranings.
In PATCH_COMMAND, use patch instead of bzr patch if patch or patch.exe is found (mandatory to use msys2 because bzr patch does not work when using msys2)
2014-04-03 13:55:02 +02:00
Marco Serantoni 1c232f5608 [MacOSX] Support for kiface in bundles, workaround for some cairo issues 2014-03-22 12:35:33 +01:00
jean-pierre charras 262ec8920a Minor fixes for Windows: move resources from dso to .exe, to have the application icon in executable, and therefore shown in shortcuts.
pcb_calculator: minor coding style fix.
2014-03-22 09:28:39 +01:00
Dick Hollenbeck 6bfff89fe5 merge tip in, resolve. 2014-03-20 01:24:33 -05:00
Dick Hollenbeck 2c67c3ff80 * KIWAY Milestone A): Make major modules into DLL/DSOs.
!   The initial testing of this commit should be done using a Debug build so that
    all the wxASSERT()s are enabled.  Also, be sure and keep enabled the
    USE_KIWAY_DLLs option.  The tree won't likely build without it.  Turning it
    off is senseless anyways.  If you want stable code, go back to a prior version,
    the one tagged with "stable".

*   Relocate all functionality out of the wxApp derivative into more finely
    targeted purposes:
    a) DLL/DSO specific
    b) PROJECT specific
    c) EXE or process specific
    d) configuration file specific data
    e) configuration file manipulations functions.

    All of this functionality was blended into an extremely large wxApp derivative
    and that was incompatible with the desire to support multiple concurrently
    loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
    An amazing amount of organization come from simply sorting each bit of
    functionality into the proper box.

*   Switch to wxConfigBase from wxConfig everywhere except instantiation.
*   Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
    PGM_SINGLE_TOP,
*   Remove "Return" prefix on many function names.
*   Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
*   Fix building boost for use in a DSO on linux.
*   Remove some of the assumptions in the CMakeLists.txt files that windows had
    to be the host platform when building windows binaries.
*   Reduce the number of wxStrings being constructed at program load time via
    static construction.
*   Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
    these functions are useful even when the wxConfigBase comes from another
    source, as is the case in the KICAD_MANAGER_FRAME.
*   Move the setting of the KIPRJMOD environment variable into class PROJECT,
    so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
*   Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
    its child wxFrames and wxDialogs now have a Kiway() member function which
    returns a KIWAY& that that window tree branch is in support of.  This is like
    wxWindows DNA in that child windows get this member with proper value at time
    of construction.
*   Anticipate some of the needs for milestones B) and C) and make code
    adjustments now in an effort to reduce work in those milestones.
*   No testing has been done for python scripting, since milestone C) has that
    being largely reworked and re-thought-out.
2014-03-19 19:42:08 -05:00
Maciej Suminski 151826b206 Upstream merge. 2014-02-21 11:05:28 +01:00
jean-pierre charras d6f348f41e Remove duplicate icon apply.svg (use ckecked_ok.svg instead which is the same icon).
Add a workaround to fix a new bug in wxWidgets 3.0 ( Windows specific ) which shows icons only with a size = 16x16 in menus which have attribute wxITEM_CHECK
2014-02-07 20:32:08 +01:00
Maciej Suminski 25dfbcd39f Upstream merged. 2014-02-07 09:52:47 +01:00
Dick Hollenbeck 4f26386e8d Initial KIWAY (modular-kicad) work. Various tweeks. 2014-02-03 09:10:37 -06:00
Dick Hollenbeck 741bfb685b Another attempt at wxFrame::SaveSettings() standard infrastructure. 2014-02-02 14:18:10 -06:00
jean-pierre charras ce6b907fe3 Add specific bitmaps in export IDF and export DSN menus.
Add missing calls to Show( false ) to some main frames (Kicad, eeschema, gerbview), to force config saving when closing these windows.
Code cleanup and minor coding style fixes  in footprint_wizard_frame
2014-01-29 18:01:42 +01:00
Maciej Suminski c3c7b2e9cc Merged the netnames branch. 2014-01-28 11:59:04 +01:00
Dick Hollenbeck c63fa6ff31 Add EDA_BASE_FRAME::Show() and call SaveSettings() only from there for all derived wxFrames. Remove calls to SaveSettings() elsewhere. 2014-01-27 19:29:26 -06:00
Dick Hollenbeck 1c0f034bca Make KiCad compile with minimal warnings against SVN HEAD of wxWidgets as of today. 2014-01-07 19:34:04 -06:00
Maciej Suminski 537d82fb98 Upstream merge. 2014-01-06 10:29:31 +01:00
Marco Serantoni 4d139b590f [MacOSX] Adding better support for Retina Display (NSHighResolutionCapable) 2013-12-31 12:03:02 +01:00
jean-pierre charras a455ab4a90 Fix bugs 1264236, 1264238, 1264254 2013-12-29 12:01:54 +01:00
Maciej Suminski 32065b339a Added const modifiers where applicable (PICKED_ITEMS_LIST).
Added PICKED_ITEMS_LIST::FindItem().
2013-12-18 13:27:18 +01:00
jean-pierre charras 5f01f123de All: GetBoundingBox returns now a const EDA_RECT.
Pcbnew: Code cleaning and bug fix in autoplace functions
Dialog exchange footprints has now a separate button to update the .cmp file, only on request.
2013-11-24 18:48:14 +01:00
jean-pierre charras 9f9f2ed380 Minor code cleaning: Remove unused file, remove obsolete or useless defines 2013-11-15 10:28:31 +01:00
Maciej Suminski e13f862145 Merged upstream. 2013-10-28 21:34:06 +01:00
jean-pierre charras dd64b2f284 3D board display: better rendering of the board: the board polygon outlines (generated by the specctra function) is now used to create the 3D body of the board. 2013-10-04 10:42:09 +02:00
jean-pierre charras d368739731 Gerbview: fix incorrect printing of negative objects, when using black and white option.
Eeschema: better name for m_SheetList (changed to m_SheetPath) member of  class NETLIST_OBJECT.
2013-09-29 20:24:38 +02:00
Maciej Suminski 8e472c736a Merged upstream. 2013-09-20 17:54:35 +02:00
Maciej Suminski c00533a150 Merged kicad-gal 2013-09-20 15:48:27 +02:00
Maciej Suminski 6d15131231 Some more missing D()->DBG() changes. 2013-09-10 17:07:46 +02:00
jean-pierre charras 684bfad0af Cleaning code for PCB_LAYER_BOX_SELECTOR class, and use it in edit dimension dialog. 2013-09-01 20:38:11 +02:00
Dick Hollenbeck efb34166ea *) retain grid origin in the BOARD and save it in legacy and kicad board files.
*) add hotkey for setting the grid origin as 'S', in board editor, module editor.
*) re-position the function interface for cursor movement from BASE_SCREEN into
   class EDA_DRAW_FRAME.  This is a prelude to getting rid of BASE_SCREEN or
   splitting it up.
2013-08-03 00:15:23 -05:00
jean-pierre charras 5c247857d3 Replace in EDA_TEXT::Draw the parameter EDA_DRAW_PANEL* aPanel by EDA_RECT* aClipBox, which is the actual parameter used by Draw.
This change make more easy to  use this function when a EDA_DRAW_PANEL canvas is not used to draw texts.
Remove dead code in worksheet.cpp.
2013-06-29 11:52:22 +02:00
jean-pierre charras 820153c7d4 Gerbview: remove fully outdated code (about reading DCode files) and fix erroneous comments. 2013-06-28 12:49:43 +02:00
jean-pierre charras 10352b1df5 Minor fixes. Gerbview: fix a collision name for GetLayout method. 2013-06-27 21:12:01 +02:00
Dick Hollenbeck 8ccf0320b4 1) Add "rules" to base of tree for copying into BZR_HOME/rules.
File "rules" has instructional text as comments near top.

2) Convert all text files in repo to LF line ending form.
   Any checkout done with "rules" in play will convert the working
   tree to native line ending, while keeping repo as LF line ending.
2013-05-25 23:36:44 -05:00
jean-pierre charras 001723e077 Worksheet code: cleanup and remove useless parameters. 2013-05-22 10:45:25 +02:00
jean-pierre charras 26a3029a88 Remove duplicate code to draw and to plot title blocks. 2013-05-21 09:18:25 +02:00
jean-pierre charras 6b0980d964 Gerbview: fix bug #1176538 (incorrect flashed items size, when defined by aperture macros) 2013-05-18 18:56:03 +02:00
Dick Hollenbeck 6fa4f1e6ac remove non-UTF8 encoded characters from source tree & format fix 2013-05-13 12:30:27 -05:00
Lorenzo Marcantonio 69b7c2a1b6 Removed some spurious float casts
(explanation: float is implicitly promoted to double anyway, it's only useful
for storage; also a fp variable forces conversion of other int in the expression
without needing a cast)
Typo fixes in some comments 'floatting' -> 'floating' :D
2013-05-07 19:31:52 +02:00
Lorenzo Marcantonio d00c83cde9 Migrated the interfaces accepting angles to the double type
The plan goes like this:
- eeschema still uses int in decidegrees
- all the other things internally use double in decidegrees (or radians
  in temporaries)
- in pcbnew UI the unit is *still* int in decidegrees

The idea is to have better precision everywhere while keeping the user with int i
angles. Hopefully, if a fractional angle doesn't come in from the outside, everything
should *look* like an integer angle (unless I forgot something and it broke)

When the time comes, simply updating the UI for allowing doubles from the user should
be enough to get arbitrary angles in pcbnew.
2013-05-05 09:17:48 +02:00
Lorenzo Marcantonio cb49ca5ae2 More int casts to rounding conversions 2013-05-04 13:57:09 +02:00
Lorenzo Marcantonio 78e41187b3 Moved utilities for angles in trigo.h
New conversion routines and sin/cos implementation for angles in decidegrees
2013-05-02 20:06:58 +02:00
Lorenzo Marcantonio 0e903dba5b Angle and distances cleanup (preparing for angles in doubles)
- Removed spurious int casts (these are truncated anyway and will break
  doubles)

- Applied the Distance, GetLineLength, EuclideanNorm, DEG2RAD, RAD2DEG
  ArcTangente and NORMALIZE* functions where possible

- ArcTangente now returns double and handles the 0,0 case like atan2, so
  it's no longer necessary to check for it before calling

- Small functions in trigo moved as inline
2013-05-01 19:32:36 +02:00
Dick Hollenbeck 1f3b3d681c fix some compiler warnings 2013-04-18 12:03:47 -05:00
Lorenzo Marcantonio 4cbbce3aa6 Removed ugly usage of an extra layer slot for the layer count in gerbview
Fixed layer picker for exporting to pcbnew
Realigned pcb layer name with class BOARD
2013-04-10 09:03:19 +02:00
Lorenzo Marcantonio 42709330e0 Better strings for the translators (converted concatenations to formats) 2013-04-09 19:49:01 +02:00
Lorenzo Marcantonio b525e3be55 Factored out text anchor drawing
More layer classification cleanup
2013-04-09 18:00:46 +02:00
Lorenzo Marcantonio 204d085b64 More cleanup on layer code usage
Better description for entities on right click menu and panel
Typo fixes and some comment reformats
2013-04-07 13:55:18 +02:00
jean-pierre charras ca4a3651c0 Gerbview, layer manager: add option (popup menu) to always keep layers not visible but the active layer, even when the active layer is changed.
Pcbnew: fix swig warning for operator EDA_COLOR_T::++  (changed to function EDA_COLOR_T:: NextColor)
2013-04-06 14:01:53 +02:00
Lorenzo Marcantonio d12a45923b More work on EDA_COLOR_T and layers.
In particular the new mechanism for handling extended color palettes is in place,
included renaming the ini keys and saving the color name instead of its index; this means better forward compatibility with palette changes.

Since ini keys are changed, colors will be reset
2013-04-04 23:35:01 +02:00
Lorenzo Marcantonio 0dd413a711 Removed unused defines 2013-04-01 07:53:38 +02:00
Lorenzo Marcantonio 9fd79dfa91 Implemented the LAYER_NUM typedef (LAYER was already taken as a class name...) to represent a layer number. 2013-03-31 15:27:46 +02:00
Lorenzo Marcantonio 27ee815742 Minor flags and layer mask cleanup 2013-03-30 20:55:26 +01:00
Lorenzo Marcantonio e0303a4558 - New typedef LAYER_MSK to encapsulate a layer bitmap
- Renamed ReturnMaskLayer to GetLayerMask (since it's a plain getter)
2013-03-30 18:24:04 +01:00
Lorenzo Marcantonio 4865a68fa0 Extremely trivial stuff (mostly cosmetics) 2013-03-28 07:40:19 +01:00
jean-pierre charras 93a8e7b395 Pcbnew: print dialog: code cleanup and bug fixes (added some fixes from Sergey A. Borshch) 2013-03-11 20:30:58 +01:00
jean-pierre charras 1ae31edb9a Gerbview: Minor fixes 2013-03-06 20:32:59 +01:00
jean-pierre charras 4343eb5b8d Fix Bug #1132416. Minor update in templates. 2013-02-24 18:31:18 +01:00
Wayne Stambaugh 0564cbc70c Minor dialog spacing, grammar, and sizer fixes. 2013-02-19 14:43:48 -05:00
Emmeran 6a54a198ca converted linux to dos file endings for wxfb files 2013-02-12 05:30:28 +01:00
Emmeran 95213372fe moved changes to dialogs into fbp files 2013-02-12 05:18:22 +01:00
Emmeran 226b877ab9 tabs converted to spaces except wxstruct.h 2013-02-12 04:56:46 +01:00
Emmeran 0bdf5bac72 added option to allow zooming around the crosshair instead of the center; can be enabled via options or by holding alt while using the mousewheel 2013-02-02 20:10:48 +01:00
Dick Hollenbeck 017fe9c4d4 fix compiler warnings with gcc 4.6.3 on x86_64 linux 2013-01-23 10:13:42 -06:00
jean-pierre charras 9ededca9d7 Gerbview: Fix a minor but annoying issue in gerbview config: colors setup is broken when running a testing version after an old gerbview version (due to a bug of this old version which breaks the color config) 2013-01-21 21:02:07 +01:00
Wayne Stambaugh f8a56d446f Base object decoupling improvements.
* Improve MSG_PANEL_ITEM to handle message panel information.
* Create containers for passing message panel items between objects and
  the message panel.
* Rename EDA_ITEM::DisplayInfo to EDA_ITEM::GetMsgPanelInfo.
* Remove all direct manipulation of EDA_DRAW_FRAME from all objects derived
  from EDA_ITEM.
2013-01-12 12:32:24 -05:00
jean-pierre charras 2dd5bcea2f Gerbview: add option to show negative objects. 2013-01-06 14:31:49 +01:00
jean-pierre charras 8653e362b2 Pcbnew: board editor: allows pad edition by hotkey 'E' (was accessible only by mouse button right click)
All: minor code cleaning and very minor bug fixes.
2012-12-27 17:42:41 +01:00
Wayne Stambaugh 63b884558a Doxygen warning fixes. 2012-12-18 08:54:44 -05:00
Wayne Stambaugh 84c7b07e02 Pcbnew print fixes and improvements.
* Fix offset errors when scale factor greater is than one.
* Changed behavior of fit in page when not drawing border and
  title block to fit board outline in page.
* Fix offset errors when mirroring (still not 100% correct on MSW with
  wxWidgets 2.9.4).
* Lots of the usual code cleaning and simplifying.
2012-11-28 20:50:58 -05:00
marco. eb3ba80643 MacOSX: disabling BufferedBitmap of OSX in gerbview, not supported nor accelerable and bitmap becomes too large in case of retina display to be usable 2012-11-20 20:19:24 +01:00
Dick Hollenbeck 28222961dd fix ownership issue in wxFFile vs. FILE_LINE_READER 2012-10-24 13:42:39 -05:00
jean-pierre charras 7c0af1bf9d More dialogs derived from DIALO_SHIM 2012-10-04 08:57:15 +02:00
marco. 0355119044 [MacOSX] Updated Icons - Document ones still missing :( 2012-09-27 19:20:44 +02:00
jean-pierre charras b660b033ad All: remove macros MAX, MIN, ABS from macros.h and replace these macros by std::max, std::min and std::abs (mainly found in old code). 2012-09-22 13:19:37 +02:00
Dick Hollenbeck 210a7036db switch all <math.h> includes to <cmath> includes on an attempt to dodge some abiguous references to atan2() 2012-09-21 12:02:54 -05:00
jean-pierre charras 819589cf05 All: fix most of Doxygen warnings. 2012-09-12 19:28:55 +02:00
jean-pierre charras 93ebdb2cd0 All: better code to handle opened frames libview, libedit, modview, modedit.
Other minor fixes.
2012-09-12 11:53:11 +02:00
jean-pierre charras b810135e4e Code cleaning, minor fixes and minor coding style fixes. wxWidgets 2.9.4 compatibility fix( deprecated function MakeModal ) 2012-09-11 21:03:21 +02:00
Lorenzo Marcantonio e771112259 Enforced EDA_COLOR_T type and minor const-ification 2012-09-02 14:06:47 +02:00
Lorenzo Marcantonio 082d901d60 Encapsulated drawmode as an enum for type checking 2012-09-01 15:38:27 +02:00
Lorenzo Marcantonio fef8347176 Script plotting patch 2012-08-29 18:59:50 +02:00
jean-pierre charras 1f277fd66d Remove Kbool from Kicad. Use Clipper instead. 2012-08-04 11:43:27 +02:00
jean-pierre charras d9ed8a3085 Pcbnew: automatic selection of plugin when loading a file with .kicad_pcb extension from history list.
Very minor other fixes
2012-06-14 21:10:32 +02:00
jean-pierre charras 30c7e31839 Very minor fixes. 2012-05-19 21:04:03 +02:00
jean-pierre charras ea467e6730 Pcbnew: fix bug Bug #1001107 (Solder Mask Ratio Clearance bad value)
Because this bug could create bad values in footprint libraries, this parameter is now checked
when reading a footprint description in legacy format
2012-05-18 10:33:57 +02:00
jean-pierre charras ff66db7b6f Gerbview: fix incorrect processing of ICI command in Excellon drill files. 2012-05-10 13:02:44 +02:00
jean-pierre charras f6551172d2 Fix capitalization issues in title bar and config files (broken by bzr rev 3543) 2012-05-10 08:25:27 +02:00
Dick Hollenbeck 86e04b4fb3 more nanometer work, see comment at line 66 of pcbnew/classpcb.cpp 2012-05-06 15:10:43 -05:00
jean-pierre charras ba96329648 Gerbview: Fix a compil issue in my last commit. 2012-05-06 21:29:52 +02:00
jean-pierre charras a3f83d771f Fix grid selection issue when starting Eeschema or Gerbview:
Eeschema (also Libedit and Libview) starts always to the default grid (50 mils)
Gerbview starts with the last selected grid, but the validity is tested.
In Pcbnew the grid value is always displayed, so it should always be good.
2012-05-06 18:55:51 +02:00
jean-pierre charras 4125ea7789 Gerbview: remove dependencies from Pcbnew.
Should allow Pcbnew code easier to change and Gerbview code more understandable and easier to maintain.
Code cleaning (remove dead code, add comments).
Minor other enhancements.
2012-05-04 19:44:42 +02:00
jean-pierre charras 758f22161a All: change MILS_TO_IU_SCALING_FACTOR constant to IU_PER_MILS ( and MM_TO_IU_SCALING_FACTOR to IU_PER_MM)
Also fix bug 985654.
2012-04-26 23:34:20 +02:00
jean-pierre charras 3b671e09d1 All: change MILS_TO_IU_SCALING_FACTOR constant to MILS_PER_IU ( and MM_TO_IU_SCALING_FACTOR to MM_PER_IU)
Also fix bug 985654.
2012-04-26 22:21:31 +02:00
jean-pierre charras a00df5b330 commit missing files 2012-04-25 21:46:30 +02:00
jean-pierre charras fa3ebc4043 Define MM_TO_IU_SCALING_FACTOR (scaling factor from mm to internal units) only in convert_to_biu.h
Other scaling factors (MILS_TO_IU_SCALING_FACTOR and DECIMILS_TO_IU_SCALING_FACTOR)
also defined only in convert_to_biu.h.
Allows different scaling value for Gerbview.
Needs more tests.
2012-04-25 21:33:24 +02:00
Dick Hollenbeck c24863c078 // Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did.  This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.


#include <stdio.h>
#include <assert.h>
#include <limits.h>

//-----<KiROUND KIT>------------------------------------------------------------

/**
 * KiROUND
 * rounds a floating point number to an int using
 * "round halfway cases away from zero".
 * In Debug build an assert fires if will not fit into an int.
 */

#if defined( DEBUG )

// DEBUG: a macro to capture line and file, then calls this inline

static inline int KiRound( double v, int line, const char* filename )
{
    v = v < 0 ? v - 0.5 : v + 0.5;
    if( v > INT_MAX + 0.5 )
    {
        printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
    }
    else if( v < INT_MIN - 0.5 )
    {
        printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
    }
    return int( v );
}

#define KiROUND( v )    KiRound( v, __LINE__, __FILE__ )

#else

// RELEASE: a macro so compile can pre-compute constants.

#define KiROUND( v )  int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )

#endif


//-----</KiROUND KIT>-----------------------------------------------------------

// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );


int main( int argc, char** argv )
{
    for( double d = double(INT_MAX)-1;  d < double(INT_MAX)+8;  d += 2.0 )
    {
        int i = KiROUND( d );

        printf( "t: %d  %.16g\n", i, d );
    }

    return 0;
}
2012-04-19 01:55:45 -05:00