Archive for the 'Programming' Category

Text2D class

At work, I’ve been working on a new Java3D project.  Java3D has been great so far, and I’ve gotten a simple visualization program up and running in two weeks.  Today, I had to figure out how to determine the actual width of a Text2D object.  Creating a BoundingBox with the Text2D object’s getBounds() method doesn’t actually help, since it seems the dimensions are always a power of two.  I needed the actual width (the height can be calculated by multiplying the font size by the the rectangle scale factor), but the bounds returned didn’t give the the value I needed; it was close, but I needed to position the text to create an annotated axis.

My solution?  I had to rewrite the Text2D class.  I read a forum that mentioned this as a solution, but it didn’t give the code or how to do it.  If you go to the Java3D website (https://java3d.dev.java.net), you can browse the source code.  The Text2D class is located in the j3d-core-utils subproject.  I just copied the source file, added two private variables (height and width), created accessor methods getWidth and getHeight, and stored the height and width when it is calculated in the setupImage method.  Just change the package name and you can use the new class the same way the regular Text2D class is used.

What I don’t understand is, why didn’t Sun or the community in general do this?  It’s a really simple fix.  How do people even use the class if they can’t accurately determine how much space the actual text uses?  I’ll post the code (with the simple modifications) tomorrow.

Text2D.java

Compiling Firebird 2.1.0 for OSX using Mono 1.2.6

I’m thinking of doing a project with C#, and I’d like to use an embeddable database, so I browsed the interweb and found this interesting project: http://www.firebirdsql.org/. I think this project is one reason Firefox had to change it’s name a second time.

The source distribution for Firebird 2.1.0 has a solution file for building on Windows, and a couple makefiles to build at the command line. The only makefile that might have worked, NETProvider/build/linux/makefile contains odd errors that do not allow me to compile the sources successfully. This is the first error:

make
makefile:40: *** multiple target patterns. Stop.

First, I’m not sure why it’s in there, but it contains a start and end div tag. I’m pretty sure that’s not allowed in a makefile, so you can just remove the start and end tag. Inside the makefile, there are several make rules that span multiple lines, and they are not “continued” properly. The simplest fix is to remove the newlines for each of the rules that span more than one line. For example:

COMMON_RESOURCES =
-resource:${RESOURCES}/isc_error_msg.resources...

Needs to be changed to:

COMMON_RESOURCES = -resource:${RESOURCES}/isc_error_msg.resources...

This has to be repeated for SCHEMA_RESOURCES, and the newlines need to be removed from PROVIDER_FLAGS, PROVIDER_TESTS_FLAGS, the compile line of the UnitTests.dll rule, and the copy command that spans two lines.

Next, move the all: rule down to the targets section. I’m not sure why it’s so high in the makefile.

If you run make at this point, you’ll receive an error:

error CS1566: Error reading resource file `../../source/FirebirdSql/FirebirdSql/Data/Schema/FbMetaData.xml'

The SCHEMA_RESOURCES variable has an extra FirebirdSql in the path to FbMetaData.xml. You need to remove it.


error CS2001: Source file `../../source/FirebirdSql/Data/UnitTest/*.cs' could not be found

This error exists because that path should point to UnitTests. Change the PROVIDER_TESTS_SOURCES variable.

Since i don’t have nunit.framework.dll, I had to compile it and install it. I’m sure you can figure it out with google. I loaded the nunit_VS2005.sln file into Monodevelop and only compiled the nunit.framework.dll assembly, and installed it using gacutil -i nunit.framework.dll.

Next, -reference:System.Transactions.dll needs to be added to the PROVIDER_TESTS_FLAGS variable. Also, -reference:System.Configuration.dll needs to be added to the same variable to fix the error CS0103: The name `ConfigurationManager' does not exist in the current context messages.

After running make again, I got error CS3002: Return type of `FirebirdSql....BuildConnectionStringBuilder()' is not CLS-compliant and two other similar messages. Because I’m not a C# expert, I just googled it, and placed [CLSCompliantAttribute(false)] above all the offending methods in the BaseTests.cs file. You’ll also have to do the same for the offending method in FbConnectionTest.cs. I’m not worried if it’s compliant or not, since I just want to use it with C#.

After all this, it finally complies! Unfortunately, when I try to install it using the gacutil, it refuses:
Failure adding assembly to the cache: Attempt to install an assembly without a strong name.

I added -keyfile:FirebirdSql.Data.FirebirdClient.snk to the end of the FirebirdClient.dll compile command, and everything compiled and installed fine. I haven’t tested the library to tell if it works, but that’ll be another post.

Modified makefile