Just another WordPress.com site

DrawGin, 12.26.2012 status

After 18 months I’ve finally started to code on the DrawGin library again and made the following changes.

  • * Refactored project directory structure.
  • ** Added VS 2008 solution file (no longer need cmake to build one).
  • Some code cleanup.
  • Fix bug when decoding class maps with multiple sections and added additional logging to help locate said bug.

In the VS property page for DrawinApp, added the following line to the Debugging/Command Arguments section:
–v=4 –log_dir=$(OutDir)\logs –alsologtostderr=1 –drawing=C:\Users\Paul\Documents\TestDwgs\TestDwg3.dwg

Decoding the Objects section is still a todo item. Once completed the library should be able to read AutoCAD R14 drawing files.

* The CMake projects files have not been updated to reflect the changed directory structure.  Then means creating projects/solutions for your favorite IDE is temporarily broken.

December 26, 2012 Posted by | C++ Programming, DrawGin, gcc | , , , , , | Leave a comment

DrawGin, 06.01.2011 status

The DrawGin library is rapidly taking shape and able to read most sections of an AutoCAD R14 formatted drawing. The next section to code up is the area where AcDbObject and AcDbEntity derived objects are stored (section 6 below). For the purpose of deserializing the bit encoded drawing data, sections 1, 2, 3, 4, 5 are completed.

  1. Drawing File Header – Defines where key sections are located within the drawing file.
  2. Preview Image – Bitmap image created when drawing was last saved.
  3. Header Variables – various setting variables associated with the drawing file.
  4. Classes Map – Holds information about various application defined classes that are used (instances of) in the drawing.
  5. Objects Map – Tells the file position of each object stored in the drawing (with AutoCAD object handle)
  6. Objects – The object instances referenced in the Objects Map (these are AcDbObject and AcDbEntity derived).

Most of the drawing format is defined at the bit level, which require special IO routines found in the OcBs directory (OcBitStream). The OcBsStreamIn class handles reading the various bit level data types and keeps track of the running CRC calculation. The stream also has a 4K memory buffer and handles huge 100 meg files, no problem.

Class DwgArchiveIn (will be renamed later to OcBsDwgArchive) is an archive class that will work much like MFC’s CArchive.

Classes in the OcDb represent the various data types that make up a drawing. Most of the classes will have a one-to-one similarity by name to those found in Autodesk’s ObjectARX SDK. At this time DrawGin is not going for ObjectARX compatibility, so member function names and signatures will not be the same.

Future blog entries will delve into the framework and implementation details. For now just wanted to post a quick status update.

June 1, 2011 Posted by | C++ Programming, DrawGin, gcc | , , , , , | Leave a comment

Visual C++ Code Formatting with AStyle

Visual Studio VBA macro to format the current C++/h document using the open source code formatter AStyle. Simply copy the macro to the “Macros->Module1” is Visual Studio, then hookup a hot key to it.

Download AStyle from http://astyle.sourceforge.net/ and extract to a directory (code will look in the download directory off the user’s home directory). Update the shellCmd string variable with any formatting options AStyle should apply (http://astyle.sourceforge.net/astyle.html).

Format string “-A4Uxpfn”
-A4 = stroustrup style
-U  = unpad paren
-x  = delete empty lines
-p  = pad operators
-f  = break blocks
-n  = do not retain backup

Code Snippet
  1. Public Sub formatDocWithAStyle()
  2. Dim fileName As String
  3. Dim textDocument As TextDocument
  4. Dim startPoint As EnvDTE.EditPoint
  5. Dim endPoint As EnvDTE.EditPoint
  6. Dim text As String
  7. Dim shellCmd As String
  8. Dim procId As Integer
  9. If DTE.ActiveDocument Is Nothing Then
  10. Return
  11. End If
  12. fileName = Environ$(“TEMP”) & “\formattedCode”
  13. shellCmd = “””” & Environ$(“HOMEPATH”) & “\Downloads\AStyle\bin\AStyle” & “””” & ” -A4Uxpfn “ & “””” & fileName & “”””
  14. textDocument = DTE.ActiveDocument.Object
  15. startPoint = textDocument.StartPoint.CreateEditPoint
  16. endPoint = textDocument.EndPoint.CreateEditPoint
  17. text = startPoint.GetText(endPoint)
  18. My.Computer.FileSystem.WriteAllText(fileName, text, False)
  19. procId = Shell(shellCmd, AppWinStyle.Hide, True, 30000)
  20. If procId = 0 Then
  21. text = My.Computer.FileSystem.ReadAllText(fileName)
  22. startPoint.ReplaceText(endPoint, text, vsEPReplaceTextOptions.vsEPReplaceTextTabsSpaces)
  23. End If
  24. End Sub

January 23, 2011 Posted by | Code Formatting | , , , , | 1 Comment

Installing latest gcc on Snow Leopard

I decided to install gcc 4.5.1 via Macports and the process didn’t exactly go smoothly. IIRC, the initial error was something about base_file.cc not being find. I’m not sure what caused the problem, however the fix was to temporarily rename the directory /opt/local to /opt/local-temp. The only packages installed in /opt/local/ are python 2.6, git, and Qt4.7.

So the basic steps if you have problems with the install using Macports is

cd /opt
mv local local-temp
sudo port clean gcc45
sudo port selfupdate
sudo port upgrade outdated
sudo port install gcc45

Towards the end of the build process there was another error about libpng being wrong or something. Simply reinstalling libpng via macports resolved the issue and allowed gcc finish building.

sudo port clean libpng
sudo port install libpng
sudo port install gcc45

Afterwards, rename /opt/local-temp to /opt-local.

If you type gcc –version at the command line the version install with XCode will probably run. This is because the Macports version is named gcc-mp-45. Using Macports install gcc_select.

sudo port install gcc_select

gcc_select –l will list the available versions of gcc, and gcc_select mp-gcc45 will make version 4.5 the default. This changes the symbolic link for /opt/local/bin/gcc. I also had to add the new symbolic link to /usr/local/bin/gcc (make a copy of the original) in order to get everything to work correctly.

October 11, 2010 Posted by | C++ Programming, gcc, Macports | , , , , , | 1 Comment

WGS84 Ellipsoid Calculations

(source code links below)
12/7/2010, added support for building as a DLL and using within Microsoft Excel VBA.

In late 2008, I was in negotiations with an aviation company to write some navigation design software. I use to work for the company and was already familiar with their software stacks and engineering processes. Quite a few of the applications the company uses, I had written or helped implement. The chances of actually getting the contract were slim though. Internal growth of the company was fast, and different departments were motivated to go a different direction than the department I was in talks with.

Even though the chances of getting the contract were slim, I wanted to get a jump on some crucial code that would be required from the onset. So I set out on October 15, 2008, to write all the formulas described in FAA Order 8260.54A, Appendix 2, and a test harness for the data published in attachment C of the same document.

Initially I figured it would take 2 to 4 weeks to write the library and test harness based on the completeness of 8260.54A. Almost immediately, I discovered the document to have many errors and omissions, which caused days long investigations into why the formulas didn’t produce the expected test results (the projects code, comments and file Application test Results.txt document some of the problems and how they are resolved).

On December 18, 2008, I finished the work, had no contract, but was proud that I’d resolved each and every formula in Appendix 2 and they produced the expected test results. Now, a year and a half later, I’m releasing the code for the formulas and test harness.

I wrote a standalone WGS84 Geodesic Calculator (beta) for Windows based on the formulas, and some people from the GeoCache community have used it to create and solve complicated puzzles.

The hardest part about releasing the code was which license to choose. Ultimately I decided for the liberal Apache License, Version 2.0, and it’s my contribution to the open source community.

WGS84 Ellipsoid Calculation Types

Arc Intercept Geodesic Locus Intersect Point on LocusP
Course Intersect Geometric Mean Meridional Point to Arc Tangents
Direct Arc Length Locus Arc Intersect Pt is on Arc
Discretized Arc Length Locus Course at Point Pt is on Geodesic
Distance Intersection Locus Intersect Pt is on Locus
Distance to LocusP Locus Perpendicular Intercept Tangent Fixed Radius Arc
Distance to LocusD Locus Tangent Fixed Radius Arc Vincenty Direct
ECEF Perpendicular Intercept Vincenty Inverse
Geodesic Arc Intercept Perpendicular Tangent Points

There are a few other implemented formulas which are support to the ones listed above.  Also, the TerpsTest code for validating the formulas is a good source to see how to use the formulas in your own code.

Available Source Code

The GeoFormulas and TerpsTest (test harness) code is hosted on GitHub, and released under the Apache License, Version 2.0. Note: TerpsTest requires Boost::RegEx. Outside of STL, GeoFormulas is not dependent on external libraries.

The source code for the standalone Windows WGS84 Geodesic Calculator is not available at this time.

July 14, 2010 Posted by | Ellipsoid, FAA, WGS84 | , , , , , , , , | 3 Comments