About this blog

Welcome to Ha Le's Work and Research Blog. This page contains information and experience that I've collected during my college's years and other work experience. The topics included are Software development (C++ mainly), Robotics Technology and other related fields.

Search This Blog

Friday, June 25, 2010

Komodo IDE Debugging setup for PHP projects (e.g. Drupal)

New direction: Web development with Drupal, and Flash.

The last few months I've been really busy with work so this blog hasn't got updated as much as I would like to. Now I have a bit more time, and my work now revolves a lot more around web applications: CMS (Drupal), Flash development etc. So the posts on this blog will be experience, tutorial, tips or tricks that I've picked up along the way.

Saturday, February 20, 2010

Viewer structure in OpenCascade, integrated with Qt4


When designing a CAD software with OCC and Qt, prob the first thing you would be looking at is creating a View of OCC in a Qt Widget. This allow you to control the view by the buttons and functions provided by Qt while the contents of the display and the selecting functions are controlled by OCC Classes.


This post will explore the structure of how the integration can be realized and used effectively. The following method is based on OCC Tutorial program, with modifications to adapt the use of Qt Designer, fixing incompatibility bugs when compiled with Qt4.6.1.

Above you can find the structure of the View. I'll explain the procedure of creating an object and putting it in the context and other options below:

1. To display an object, the object has to be an AIS_InteractiveObject, most commonly an AIS_Shape. This can be created by appropriate TopoDS_ objects (typically TopoDS_Shape). These are created from basic geometry (Geom_Curve etc) by BRepBuilderAPI_ functions.
Ex:

Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(-10,-20,-30);
Handle(AIS_Point) AISVertex = new AIS_Point(aPoint);
getContext()->Display(AISVertex);
You should spend time reading OCC Documentation about the above packages to have a full view of what functions they have to offer.

2. By default whey Display(AIS_InteractiveObject) is used directly, the object is displayed in Neutral Point Context (which means the base Context), where (in general) you only can select the object as whole (i.e. cannot select the edges, vertices of the object separately). To do that, follow the following procedure

  • Create a AIS_InteractiveObject
TopoDS_Shape myTestBox = MakeSimpleBox(100,200,50); Handle(AIS_Shape) AISBox=new AIS_Shape(myTestBox);
  • Create New Local Context (read AIS_InteractiveContext for detail)

getContext()->OpenLocalContext(Standard_True,Standard_True);
  • Display the object with option of allowing decomposition, update viewer, selection mode doesn't matter
getContext()->Display(AISBox,AIS_Shaded,0,Standard_True,Standard_True);
  • Activate the selection mode you want to use
getContext()->ActivateStandardMode(TopAbs_VERTEX);
getContext()->ActivateStandardMode(TopAbs_EDGE);
//getContext()->ActivateStandardMode(TopAbs_WIRE);
//getContext()->ActivateStandardMode(TopAbs_FACE);
getContext()->ActivateStandardMode(TopAbs_SOLID);
  • Note that the selection are prioritized, Vertex>Edeg>Wire>Face>Solid.
I kept the post short but happy to answer questions regarding the matter.

Thursday, February 18, 2010

OpenCascade and Qt Integration in Windows and Linux (Window Fixs)

Something missing from last post:

In Lib, need to include $(PATH) as well.
In $(PATH) environment, needs to add the following C:\OpenCASCADE6.3.0\tools\ocafbrowser\win32\qt\lib if using DFBrowser

Saturday, February 13, 2010

OpenCascade and Qt Integration in Windows and Linux (Part 2)

On Unix, things get a bit more complicated. The following process was successful on Ubuntu 9.

1. Download OpenCascade source code (.tgz) and other packages required, for Qt, download the SDK for Linux.

2. make sure you have: build-essential, autoconf, automake1.7,  cpp-4.4, , gcc, gcc-4.4,g++, g++-4.4, java-common, libc* (i.e. libc-dev-bin), libgc*, libgcj*,libgl1-mesa*,libglu1-mesa,libgnome*,libgtk*,sun-java6*,x11*,xorg-dev,xserver-xorg* ,libsdl*
  • For those don't know, it can be done by sudo apt-get install "name of package"
  • If you don't want to bother download all these things, and you have plenty of space in your hard drive ( I used up 15Gb to get this all working), you can use this file and type into your terminal : "dpkg --set-selections < installed-software ", then, followed by "dselect". (installed-software is the filename you've downloaded).
3. Install the packages in the order Tcl, Tk, Tix, Fltk (./configure && make && sudo make install). \
4. Qt can be installed in parallel with the above package, it comes in .bin file so you have to follow (in the directory with the downloaded  ".bin"
  • chmod +x qt....(filename).bin ----------------- ENTER
  • ./qt............filename.bin
  • This would execute the installation and ... like Windows.
5. Configure OpenCascade, you HAVE TO follow the Readme.txt in OpenCascade6.3.0/ros/Readme.txt to properly configure OpenCascade, my Configure looks like this
./configure $flags --with-java-include=/usr/lib/jvm/java-6-sun-1.6.0.15/include --prefix=$INSTALL_DIR
  • to have INSTALL_DIR you need to type in these BEFORE configure
    • INSTALL_DIR=/home//.... (whatever directory you want to install OCC to)
    • in your terminal, to check type" echo $INSTALL_DIR".
  • If you install Tcl, tk etc. as default, OCC will be able to find them, as well as X11 so you don't need to specify the path. But for some reason you need to specify Java's path, it's where the file jni.h is so you can find it by "locate jni.h" (make sure you update your database first by: " sudo updatedb"
  • Take time and follow the configure procedure, if something is not right, recommendedly to "make distclean" to restart from fresh. If packages missing, check the file "installed-software" above for what I needed to get mine working
6. DON'T TYPE "MAKE" yet!!!!!!
  • Gcc4.4 somehow treats one line of code in OCC as error, so you need to fix it before making
  • Type "locate WOKUnix_FDescr.cxx" to get to that file
  • type "gedit WOKUnix_FDescr.cxx" to edit that file
  • Go to LINE 205  which has
  •  myFileChannel = open(apath.ToCString(),  O_RDONLY | O_NDELAY | O_CREAT);
  • and change that into
  • myFileChannel = open(apath.ToCString(),  O_RDONLY | O_NDELAY | O_CREAT,0664);
7. Now you can "make && sudo make install"

8. After installation, you need to add some environment variable refer to OCC and use them in your program.
To add environment variable, read this
  • I myself use /etc/environment (type "sudo gedit /etc/environment") 
  • add CASROOT="/home/ha/OpenCascade" 
  • and LD_LIBRARY_PATH="$CASROOT/Linux/lib"
  • to the end of the file, then you can use $(CASROOT)/Linux/lib (or LD_LIBRARY_PATH) to refer to your library or $(CASROOT)/inc to refer to your includes etc.
(Need to restart for this to take effect)

9. Particularly for Qt Creator, to use OCC library, in the project file .pro, specify these

INCLUDEPATH += ./GeneratedFiles \
    ./GeneratedFiles/Debug \
    $$(CASROOT)/inc   \

LIBS += -L$$(CASROOT)/Linux/lib \
    -lTKernel \
    -lTKGeomBase \
    -lTKTopAlgo \
    -lTKOffset \
    -lTKBool \
    -lTKPrim \
    -lTKFillet \
..(whatever library you want to use)

10. If there's runtime error due to missing library, go to Projects (in the QtCreator main page) in tab run, choose environment variable add/edit, there you can check if the environment vars are correct and edit if you see that the library path is missing.

Now you should be able to compile and run a Qt-OpenCascade program

I've included my .pro and .pri file so you can use that as examples



OpenCascade and Qt Integration in Windows and Linux

In my COHESIVE project, it comes to the decision of using OpenCascade as the framework for modelling and visualizing, cos it's powerful enough for our application and... free to use, and Qt as the UI development libraries due to their powerful, cross-platform tools and fantastic documentation.

My project requires the software to be cross-platform (Windows and Unix), therefore the installtion and compilation of the two libraries on both platforms is definitely the start.... But, it's not that easy....So I write this post to help those who want to use the two libraries together cross-platform.

This guide is according to my notes which is already a month old, so it might not contain all steps needed, but I'm pretty positive that it covers at least 90% of what needs to be done.... if you find error, please report here, I might be able to figure out.

1. On Windows (tested on Windows 7 and Xp)
Very easy.

  • Download OpenCascade for Windows and install.
  • Download and install MS Visual C++ Express 2008 (Free). 
  • Download Qt-OPENSOURCE for Windows and compile with VS2008 as here
  • NOTE: the Qt Creator SDK will NOT work with OpenCascade library due to it was compiled by Visual C++ while Qt SDK uses MinGW. I've tried and failed to compile OpenCascade source using MinGW, if you can, that'd be awesome if you can share.
  • Make sure you add in the following to includeyour VC++ Project properties Tools-Options-Projects and Solutions - VC++ Directories 
    • For "include file": add $(PATH)\include and $(CASROOT)\inc 
    • For Library File: add $(CASROOT)\win32\libd
    • Above assumed you used standard installation procedure for OpenCascade and Qt.
    • Make sure environment variable $PATH has the following, it might be overkilled but it worked for me, you can eliminate some if you want C:\OpenCASCADE6.3.0\ros\win32\libd;C:\OpenCASCADE6.3.0\ros;\Qt\4.6.1\bin;C:\OpenCASCADE6.3.0\3rdparty\win32\vs;C:\OpenCASCADE6.3.0\3rdparty\win32\tcltk\bin;C:\OpenCASCADE6.3.0\ros\win32\bin
    • $(CASROOT) should already be set to C:\OpenCASCADE6.3.0\ros\

  • Before compiling, make sure your linker knows it needs OpenCascade Library (VS) Projects--Properties--Configuration Properties -- Linker -- Input 
    • Then aat Additional Dependency, make sure you have (if not, just add), this again might be overkilled... but worked
    • TKernel.lib
    • TKGeomBase.lib
    • TKTopAlgo.lib
    • TKOffset.lib
    • TKBool.lib
    • TKPrim.lib
    • TKFillet.lib
    • odbc32.lib
    • odbccp32.lib
    • TKMath.lib
    • TKService.lib
    • TKV3d.lib
    • TKBrep.lib
    • TKIGES.lib
    • PTKernel.lib
    • TKSTL.lib
    • TKVRML.lib
    • TKSTEP.lib
    • TKShapeSchema.lib
    • TKG3d.lib
    • TKG2d.lib
    • TKXSBase.lib
    • TKPShape.lib
    • TKShHealing.lib
    • TKBO.lib
    • qtmaind.lib
    • QtCored4.lib
    • QtGuid4.lib
    • QtOpenGLd4.lib
    • opengl32.lib
    • glu32.lib
    • Qt3Supportd4.lib
    • comdlg32.lib
    • QtTestd4.lib

  • You should be able to compile and run the "Tutorial" code comes with OpenCascade in VS2008 and see how it works.
  • To be continued

Friday, February 12, 2010

How to start up a Software Project

Currently, I'm working as a program developer for COHESIVE project (UNL - NE, USA). My responsibility is to develop a CAD program customized to the project which involves analyzing viscoelastic material-based structure or object. The solver's already complete and my job is to create a user-friendly and integrated program implementing geometry, pre and post processing for the solver.


First step - Domain Vocabulary


This was totally brand new to me, I've been using CAD programs like SolidWorks for at least 2 years through my various projects at uni, but design one, never thought of that. So naturally, I jumped on Google and try to figure out all the concepts that need to be understood, and those are "Domain Vocabulary", this process might take you a day or two, sometime few days if it was something complicated or something you never done before. For me, the concept of how a FEA program works, how mesh are generated in code, how data is structured and how the output of the solver is manipulated were the main ambiguity that had to be addressed. Technical terms specific to the domain like tractions, body force, local mesh, global mesh etc.. were also looked at.


This process might be irritating cos you got a feeling ya not actually doing any "real" work, but it's extremely important in term of how you communicate with your clients (in my case, my supervisor), your team and your technical advisor (the one shows you the math). Imaging how're you gonna develop your software if you don't understand fully what's the client's need when it was explained in  "foreign language". It also enable you to have the choices of prioritizing the features that are most significant to the project, to be done first, if you follow the popular incremental model in software development.


Second step - Determine Needs and Constraints


This step is understood and taken by almost all programmers, but that's exactly why we have so much confidence in ourselves when analysing need and constraints that we sometime oversee details, which is disastrous for the project.


One of the things that is quite frequently missed is "Priority of Needs". Normally, customer comes to you with a description of what he wants, sometime in the form of an idea, or a procedure, or even preferred method. But one thing sometime missed out, especially in a large project, is "How the needs prioritized?", what's the most painful thing that needs to be addressed? What are extras but preferred to have? What was requested only by the customer's own interpretation of the problem (with sometime not really necessary)? 


Why these info are usually missed out? Because even the customer doesn't think about it, unless asked. Why are they so important? Because of constraints! There's never a perfect software, there's so many things to considered, commercializablity, data integrity, security, adaptablilty, mobility, cross-platform ability, user-friendly interface etc... And customers always want ... all that....and within a small budget!!! without considering what's most important! Therefore, a programmer should take the first chat with the client away, think about all his requirements and those by the programmer's own experience and perspective. Then write them all out, come to the client again with a full understanding about what each ability means to the project (product) then prioritize them with the client, in regarding to the cost of the project.


Only after that, the development process involving potential solutions, estimated cost of each, further project's requirements etc can be executed. Depends on your application, you can choose the process models most appropriate.