Developing Linux tools for an Opticians shop




This is the author after being exposure to Linux


original in es Juan Pablo Rosas Durán
es to en Miguel Angel Sepúlveda
es to en Javier Palacios Bermejo


Currently system manager for "Optica LUX" in Mexico. He has been involved with computers since the age of three, when he played with piles of punched cards in his fathers work and used Gamma10 manuals as sketch books. His professional experiences with Linux transformed him completely and since them he tries to apply open source solutions (with some success) everywhere.
At present he promotes an initiative for the development of GPLed applications for bussinesses:
He thanks LinuxFocus for the chance to share his Linux experiences and open source software.


This article dicusses how a medium sized company, focused on the development and production of eye-glasses, has used Linux and open source software to improve its customer support.


Óptica LUX


About Óptica LUX

Óptica LUX is a company devoted to the development and production of commercial sun and prescription glasses. March 2000 has been the 58th anniversary of this company, and in the last eight years it has doubled its number of retail stores. At present time it has a total of 40 retail stores.

From its beginnings Óptica LUX has promoted a policy of warrantied satisfaction for its customers, and this requires the greatest amount of knowledge of its customer basis, needs and current design preferences.

It is estimated that by the end of 1999, Óptica LUX had information about hundreds of customers. Most of this information, regarding general statistics and optometric data, where recorded in old paper notecards. All this information in its present form is of very limited use.

Our problem consisted in finding a solution to manage this information in order to improve our customer service without introducing any delays in the service provided and its quality. All this should come at no additional cost to the end product.

Typical activities in an Optics business

Before starting it is fundamental to understand the general steps a typical customer of Óptica LUX follows in order to understand the requirements for the application described later on. When a client first arrives at a store:

  1. General information about the client is taken and stored: name, address and email.
  2. The client is examined by an optometrist who performs various tests and measurements, among them the lens measurements, refraction, queratometry and measurement of the visual sharpness.
  3. Based on the previous tests the client is advised on the technologies available to solve his/hers vision problem.
  4. The client selects the technology and the frame desired.
  5. The client gives a partial or full downpayment for the work, which is forwarded to the lab for its prompt production and delivery.

To our case study of how a typical client is serviced in a retailer store we must add the following considerations in order to put things in context before writing an application:

The above analysis makes it clear that the tool needed to support our customers must be quite unique and specialized.

Unsucessfull searches

From 1990 we have studied and tested various propiertary systems specialized for optics retail stores, but none of them really satisfy all of the requirements described above. Adopting any of these commerical solutions would have required to alter significantly the way Óptica LUX interacts with its customers and manages its information, it would have also meant to pay twice as much the software value in order to pay for the modifications required. Proprietary software has the added disadvantage of making us dependent on a third party software provider.

Back in 1995 we considered for the first time to develop an in-house solution custom made for Óptica LUX needs. However when estimating the costs for licensing the platform and tools (SCO Unix and Informix), it turned out equivalent to that of opening a new retailer store! including installation, optometrics equipment and merchandise!!

It was then decided we would try to look for a viable solution that wouldn't require a huge investment in licenses. The platforms that most called our attention were coherent, qnx and Linux.

We attempted to contact coherent, but by then they ceased to exist.

Qnx had an office in Mexico (in the city of Monterrey N.L.). However their responses were limited to simply sending their advertisement brochures.

Discovering Linux

We learned about Linux thanks to an article entitled ``Linux una propuesta indecorosa'' (Linux, an indecent proposal), written by Fernando Magariños (better known in the mailing groups as ``Mancha de la Calabaza que ladra''). We sent him an email which was replied by Miguel de Icaza himself (I doubt he remembers it now). He gave us his point of view, what reinforced even more our interest towards Linux.

At first, Linux became interesting to us mainly as a ``Royalty free'' platform. However its underlying principles, its dynamism and the spirit of its community became also very important factors.

The technical support we get for Linux through mailing lists is far more effective than its commercial counterparts. Linux is a stable platform which is constantly getting better and it has a wide range of applications available.

Another factor is that information about Linux and free software is much more accessible than their proprietary counterpart, it is then very easy to get self-educated in the usage of Linux or its tools.

At present time Linux is being used in Óptica LUX not only at retail stores, but also at the main executive offices, particularly in the server side to share files and printers and to store data and execute applications developed for other UNIX machines.

We use Linux also to support the basic communications infrastructure in the company, like a PPP server, a web server, email and ftp (our small ``intranet''), and also for the control and fragmentation of the network traffic.

Lately we have started to use Linux as a desktop platform for end users, but this is a story for another time :-).

First Mistakes in Adopting Linux

The first steps are never easy, and the critical one in the case of Óptica LUX was not to convince the executive management of the technical superiority of Linux as a platform, but of making them conscious that the costs associated with developing a new system, specially one highly specialized, are very high and that it is not a very fast process.

We asked 7 companies or groups for submitting proposals for developing a solution based on Linux, but their bids far overpassed the expenses of the proprietary solutions discussed above.

Next we tried to recruit developers to create an in-house system. Unfortunately, there were still very few people really adept for this platform, and the cost of those who are available was well above the average market price, as it is understandable.

Today it is accepted that the development of open source based solutions can be more expensive than proprietary software, but the results are more satisfactory. In any way, the savings in licensing costs can be used to pay for the required development costs of applications.

Development Process

In the mid 1999 we hired a consulting group to develop a tool to process the data of our clients based on Linux and the GNU software.

The development was taken in a series of incremental steps. A first analysis of the problem gave us:

  1. A detailed design of the database
  2. Usecases for our application
  3. User Interfaces

Based on this first analysis the group developed a first prototype, which was then tested by our expert optometrist. The users provided some interesting feedback that led to modification in the requirements and a second prototype. We followed several cycles of refinement until arriving to a satisfactory product.

The features of the tools used in the development allowed us to speed up the development process, reusing and perfecting the components of the application.

The tools used can be classified in two groups: those used during analysis, design and documentation and those used during the development of the application.

Analysis, Design and Documentation Tools

Xfig  (
Tool for drawing general diagrams
Dia  (
Tool for drawing UML diagrams
VisualTCL  (
GUI Prototyping tool
LYX  (
Word processor used to write the specifications of the DB system
StarOffice  (
Word processor used writing user manual.

Development Tools

PostgreSQL  (
Database engine. Selected for its flexibility, power and its capability to manage large volumen of data.
Perl  (
Language base for the development of the application. Selected for its power, expressiveness and ease to learn for any relatively educated user.
 Tk  Module (
PERL functions for GUI development. pTk is easy to program and offers a wide range of widgets.
 DBI  Module (
PERL Functions for the management of SQL databases. High level functions that save great amount of development time.
 DBD::Pg  Module (
A specific DBI driver for postgreSQL.
Emacs  (
Development Environment used for writing, testing and debugging our applications.
CVS  (
Archival system use to maintain the code, prototypes and subprototypes. Much of the tracking effort of various revisions of the application would have been impossible without it.

Finally Our Application

It is difficult to described briefly such a highly specialized and dense tool. The script that creates the database has more than 1000 lines of SQL code, and the application itself about 15,000 lines of PERL. Therefore we will only mention the most relevant features.

The user interface

The most important feature of this application is the user interface. To facilitate the usability of the interface it was decided to design a very simple and flat interface. The expert optometrists may feel confortable and familiar given his experiences with other optics equipment.

The various elements in the interface are grouped in tabs following the methaphore of a notebook (see following figure). The graphical interface does not require the user to use the mouse to input the data. There are hot keys conveniently located to access every tab in the GUI.

The tabs in the application are as follows:

General data
contains name of the client, address and email.
Initial prescription
information regarding the initial prescription the customer was using when coming to the retail store for the first time.
Optical records
It harbours data about the state of the eyes, general health and activities, and everything you could need to fix his visual problems.
with the results of the revison and the optometric measurements from customer
Contact lenses
It's a whole module within the application. Subtabs are used to perform the necessary calculations to get the best contact lenses for each customer.
with the final specification for the glasses, where the work order will be submitted to the laboratory to make them.
where you can search for old tests, and previous sales to the customer.
the connection with the sales module, where the invoice is made, and where the work orders and factuarations for each customer are managed.

Hereafter, the most important aspects related to these data groups will be discussed.

General Data

The strongest point of this tab is how easy it is to search (and find) data. For example, you can enter a part of the neighborhoud name, select a state from the list, and the application will give you the list of postal codes fulfilling both criteria.

click on the image to get a detailed view

Instead of the neighborhoud, you can enter the district, or both names. In this case a more specific list will be provided by the system.

The postal codes, neighborhoud, district and councils from the whole country are stored in a database with more than 60000 entries. The longest search take no more than 3 seconds to make and display the postal codes list.

These searching facilities are available all along the application. If the user wants to find a person named "Juan", but whose family name could be "Perez" or "Penas", writing "Pe" in the family name box and "Juan" in the name one, after pressing the "Search" button (or the shortcut Ctrl-B) the system will supply a list with every customer fulfilling the criteria.

Customers currently served

From everywhere within the application, just pressing Ctrl-A you will get a window with all the customers being attended in this moment, allowing you to identify them with their name and access to any of their data.

click on the image to get a detailed view

Optical records

This was among the hardest tabs to develop, because it implied major changes in the pTk widget sources, especially for the frame named "Transparent and external medium reviews".

click on the image to get a detailed view

Within that frame the user is able to select any of the available checks, that are shown accompained by a list with all the possible anomalies of each eye.

click on the image to get a detailed view

As soon as the optometrist press the "check button", a cross appears close to the label of the selected check. Does anybody know an easy way to do it with VB for example?.


In the Exams tab, a rather complex set of validations are performed. When the optometricist writes down the instruments measurements and decides the correct graduation for the customer, the system checks the correctness of relations among different data and warns the user if there is any condition not fulfilled.

click on the image to get a detailed view

Contact lenses

This is the jewel of the application! This piece of code was the one that needed stronger efforts and made arise most of discussion within the development team. Most people using contact lenses can not even imagine the complexity of the amazing thing they wear on their eyes.

Contact lenses are like shoes. In the same way that there are no feets equal all over the world, there is no pair of eyes with the same visual problems.

The application is designed to help the optometrist to select the best type of contact lenses for each customer. It is impossible for the application to decide automatically the correct graduation because there are many non measurable conditions that must be taken into account (for example, those shown in the Optical records tab). However, this module is very useful as a tool to evaluate the impact of many factors over the visual sharpness of each eye.

click on the image to get a detailed view

For example, for torus-like contact lenses, the application gives to the optometrist a way to test different corrections for the deviation of the contact lenses axis (lower right corner of the previous figure). As stated before each eyes are unique, and the contact lenses suffer some slight changes to accomodate to the cornea shape, changing the final effective graduation of the eye.

Database duplication with encrypted e-mail

There are other parts of the application that are due to mention because of their unique characteristics. One of them is the mechanism to duplicate databases across internet. We were looking for the secure transmission of data from every Optics to the central data storage located at the executive offices.

This mechanism is implemented using modules available from any CPAN mirror site, and some code written for the database manager PostgreSQL, as shown in the graph below.

click on the image to get a detailed view

Actually, this development has so many interesting details that we hope to devote a future _LF_ article to it. If the editors give us such a chance :-)

Light computers

The last point to mention is the use of light computers. As stated in the introduction, one of the requirements was to use computers with the smallest size possible. Due to this, an important task was to study the better choice among second hand 486, slim and ultra-slim boxed computers, and network computers.

The most usable alternatives were:

Ultra-slim boxed computers
They were tested with a Linux distribution limited to one floppy (a minimal compressed kernel image) with the basic network configuration and a vnc client based on svgalib. This boot disk transforms a 486 (and newer) computers into graphical workstations, working with only 8Mb and not requiring hard disk.
Network computers
Neither hard disk nor floppy, with remote boot using DHCP and based on PowerPC CPU's. Although Linux support for the processor was yet under development at the time the decission was taken, there was a kernel image available via ftp (as stated on the NetStations HOW-TO).

As the critical point is the physical space we selected network computers with 9'' SVGA screens, because their size (19.05x26.67x3.18 cm) allows them to be placed anywhere within the shop.

The experience with light computers has plenty of interesting details, that we plan to show in a future _LF_ article.

Credit where credit is due

And we could not finish without giving proper recognition to the people that, with their creativity and effort, made it possible that the whole application was Linux based:

Citlali Calderón de Anda:
Liliana Araceli Cabello:
Juan José Alba
Edgar Raúl Acosta Villaseñor:
Gunnar Wolf:
Roberto Andrade Fonseca:

We believe that some part of the code could be of general interest, as the changes in the pTk widgets, the encripted e-mails sent using perl, and the programs to duplicate and syncronize the PostgreSQL databases, as well as the floppy images for graphical boot disks. Everything will be placed in the future under