----------------------------------------------------------------------------------------------------------------------------------------------------
Program Listing for:  DrawTest.java
Project:  dwgApp
Namespace:  java
----------------------------------------------------------------------------------------------------------------------------------------------------
/** * "fat port" of draw client program * current version uses Visual J++ 6 this may change though * * @author Scott Laing * @version 0.2 (pre-beta) * * notes: current VJ++ project name is visjplus1 * * goals and purpose: * * to port Draw Client away from Corba ORB piece and make it fully * funtional as a "fat client" with all drawing and saving done locally * or via direct odbc calls. previous version used CORBA as a pre-RMI * type methodology so all code ran on the server, this seems to have * introduced a variety of non-fixable problems related to the ORB * CORBA implementation itself. It is believed by myself that porting * completely off ORB will fix these and performance should be okay given * current pentium 200+ configurations used by assessors. * * New Maintenance Log * */ import dwgtest.*; import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.awt.PrintJob; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Vector; import java.lang.reflect.Array; import java.util.StringTokenizer; import ksr.DWGDrawingObject; import ksr.DWGDrawControls; import ksr.DWGDrawPanel; import ksr.DWGDrawPanelTarget; import ksr.DWGItemListener; import ksr.DWGSeparator; import ksr.*; import utility.YesNoDialog; import DWGOutputStream; /** * Basic Drawing program - does a few things. * * @author Raghu Konuru May 22, 97 * @version 1.1 * * Maintenance Log * ___________ ___ * * Oct <10, 97 RK Implemented logic to deal with the parcel drawings as a whole. * Provided access methods for each business object from creation * retrieval, manipulation, save and destruct. * * Oct 10, 97 RK Modified the parcel creation to be handled in the Drawtest and not * in the AppFrame. Added a resetRef which just sets pref = bref = fref = null. * * Oct 22, 97 RK Print works now!! * * Oct 23, 97 RK Added catch exception DBNotAvailable to validate user method. * When the database is down, it displays an error mesg and an Application * exit is performed. * * 11/7/97 DS Added a getUser() and a getParcel() method. * * 12/29/97 DS The controls now displays DFR Area on DFR drawings. This area is a constant.. * changes or edits do not change the DFR area. * 2/22/98 DS In the copyVectorToArr method added code to get the description * for DWGSymbol of type "Other".... * * 3/25/97 DS Renamed the CopyAction to displayAction this method could probably be removed * if the appropriate action is taken in the getFloor or getBasement. * * 3/26/98 DS Added a boolean value viewBasement. This is set = true during a createBasement * or a getBasement. The viewBasement is used during a print parcel to determine * if a basement is currently being viewed. If a basement is currently being viewed * then a getBasement is performed at the end of the print routine. This resets * the view. * * 4/8/98 DS Added the capability to determine if a parcel dwg is model based. * OpenAction will now set subName, modelName and isModelBased. * Therefore, this information can be reflected in the titleBar and legend. * * 4/22/98 DS Removed the Vector colors and all associated calls and functionality. * This Vector was used to get/set color in DWGDrawControls. The Vector * is no longer needed since the color CheckBox in DWGDrawControls has * been removed and colors are now set through the menu system. * * 5/15/98 DS The dispose method was modified by RK to prevent the duplicate * marker names in same server error. This error arose during the * create over existing dwg. Also, a new method killParcel was * added. This change to the IDL and TransactionManager will * require a back end "compile" when promoted. * * 4/21/99 DS Modified the signature of the saveAction from * public void saveAction() TO * public void saveAction(boolean showSaveDialog) * if showSaveDialog is true display a saveAsFinished dialog */ public class DrawTest extends Applet implements MouseListener, ItemListener, ActionListener { protected int scale; public DWGDrawPanel dp; protected DWGDrawPanelTarget dpt; protected DWGDrawControls controls; protected ScrollPane sp; protected int count = 0; public boolean parcelSaved; protected Point labelLoc = new Point(10,10); DWGParcel pref = null; DWGBldg bref = null; DWGFloor fref = null; DWGBasement fbref= null; DWG dref = null; TransactionManager tref = null; protected String s = null; protected String hostname; protected String tmarker; protected String parcel; Vector drawings; protected String marker; protected double totalArea = 0.0; protected boolean updateMode = false; public boolean parcelChanged = false; protected boolean structureSaved = false; public boolean isBasement = false; protected BOA boa; protected ORB orb; protected String user; public int curBldgIndex, curFloorIndex, curDWGIndex, nFloors, nBasements = 0; protected boolean viewBasement = false; protected String subName, modelName; protected boolean isModelBased = false; public static final short HAS_DWG = 0; public static final short OK = 1; public static final short IO_ERROR = 3; protected CalculateArea calculateArea; dwgtest.DWGPackage.dwgStruct []dTest; public void init() { Checkbox cb; parcelSaved = false; scale = 6; setLayout ( new BorderLayout()); dpt = new DWGDrawPanelTarget(); dp = (DWGDrawPanel) dpt; dp.addMouseListener ( this ); controls = new DWGDrawControls (); calculateArea = new CalculateArea(this); dp.setControls(controls); dp.setScale ( scale ); drawings = new Vector(); (controls.getScaleField()).addActionListener ( this ); add ( "South", controls ); sp = new ScrollPane ( ScrollPane.SCROLLBARS_ALWAYS ); sp.add(dp); Adjustable vadjust = sp.getVAdjustable(); Adjustable hadjust = sp.getHAdjustable(); hadjust.setUnitIncrement ( 25 ); vadjust.setUnitIncrement ( 25 ); sp.setSize ( 200, 200 ); sp.setScrollPosition(300,300); add ( "Center", sp ); } public void connect(String user) { this.user = user; tmarker = new String("ts_" + user); System.out.println("Host: " + hostname + " tmarker " + tmarker); if ( tref == null ) { try { tref = TransactionManagerHelper.bind(tmarker + ":TransactionServer", hostname); System.out.println("Bind : bound to server on host " + hostname); tref.hostname(hostname); } catch ( SystemException se ) { se.printStackTrace(); dp.displayMsgDialog ("Error"," Error: Connecting to Server. Exit and try again. " ); } } } public boolean validate_parcel(String book, String map, String item) { this.parcel = book + map + item; boolean val = false; parcel = book + map + item; try { val = tref.validate_parcel(parcel); } catch ( dwgtest.TransactionManagerPackage.InvalidParcelException se ) { se.printStackTrace(); dp.displayMsgDialog("Error","Error Validating Parcel against CASRP "); return val; } catch (SystemException se) { return val; } System.out.println("DrawTest: " + val); return val; } public boolean validate_model(String subdiv, String model, boolean isNew) { boolean val = false; this.parcel = ""; try { System.out.println("subdiv model " + subdiv + model); val = tref.validate_model(subdiv, model); if ( val ) this.parcel = tref.getModelID(subdiv,model,isNew); System.out.println("Model " + this.parcel); } catch ( dwgtest.TransactionManagerPackage.InvalidParcelException se ) { se.printStackTrace(); dp.displayMsgDialog("Error","Error Validating Model against DIMS_MODELS "); return val; } catch (SystemException se) { dp.displayMsgDialog("Error","System Exception"); } System.out.println("DrawTest: " + val); return val; } public boolean validate_user(String user, String password) { boolean val = false; connect((user.trim()).toUpperCase()); try { val = tref.validate_user(user.toUpperCase(),password.toUpperCase()); } catch ( dwgtest.TransactionManagerPackage.DBNotAvailableException se ) { System.out.println("Error validating user " + se.toString()); dp.displayMsgDialog("Database Error","Database is down." + "\n" + "Please contact help desk. System will EXIT"); ExitAction(); System.exit(0); } catch ( dwgtest.TransactionManagerPackage.InvalidUserException se ) { System.out.println("Error validating user " + se.toString()); // dp.displayMsgDialog("Error"," Error Validating Login, try again "); } catch (SystemException se) { System.out.println(" Error validating user SystemException "); } return val; } public void set_hostname(String s) { System.out.println("host dt: " +s); this.hostname = new String(s); } public String get_hostname() { return hostname; } public static void main ( String args[] ) { ORB.init(); DrawTest drawTest = new DrawTest(); if ( args.length == 1) drawTest.set_hostname(args[0]); else drawTest.set_hostname(_CORBA.Orbix.myHost()); drawTest.init(); drawTest.start(); AppFrame f = new AppFrame ( drawTest ); f.add ( "Center", drawTest ); f.setSize ( 770, 550 ); f.setVisible(true); } public void PrintAction ( Graphics print_g ) { Image img = createImage(1000,1000); Graphics pg = img.getGraphics(); pg.setColor(Color.black); pg.setFont(new Font("Aries",Font.BOLD,9)); dp.printFloor(pg); // print_g.clipRect(maxpt.x, minpt.y, (maxpt.x - minpt.x), (maxpt.y - minpt.y) ); int factor = 1000; //print_g.clipRect(10, 400, 500, 500 ); print_g.drawImage //( img.getScaledInstance ( factor, factor, Image.SCALE_DEFAULT ), //10, 10, 999,999, this ); ( img.getScaledInstance ( factor, factor, Image.SCALE_DEFAULT ), 25, 25, this ); } public void ClearAction ( Graphics g ) { dp.setFileDraw ( false ); dp.setPolygonClosed(false); dp.clearScreen(); controls.setTotalArea ((int) dp.getTotalArea()); } public void setUpdateMode(boolean flag) { updateMode = flag; } public void ExitAction() { try { tref.cleanup(); } catch ( SystemException se ) { System.out.println("Error Cleaning parcel " + se.toString()); //se.printStackTrace(); dp.displayMsgDialog("Error"," Error Cleaning Up. Contact Support. "); } } public void SaveAction(boolean showSaveDialog) { try { pref.area(dp.getTotalArea()); if ( tref.saveDWGParcel(parcel) ) { if(showSaveDialog) dp.displayMsgDialog("Information", "Save As Finished Complete"); parcelSaved = true; } else dp.displayMsgDialog ("Error ", "Save As Finished Failed , Server Error"); } catch ( SystemException se ) { System.out.println("Error saving parcel " + se.toString()); dp.displayMsgDialog("Error","Save As Finished Failed , System Error"); } } public boolean NewAction() { if ( pref != null ) { resetRef(); } curBldgIndex = curFloorIndex = 0; if ( updateMode ) { updateMode = false; parcelSaved = true; } System.out.println("Pref " + parcel); if ( !createParcel(parcel, false) ) { return false; } else { createBldg("Main Structure"); createFloor("Floor 1"); parcelSaved = false; return true; } } public void SaveAsAction ( String s ) { } public void CutAction() { editStructure(0); } public void displayAction() { getStructure(); dp.setFileDraw ( true ); dp.rePaintAll(); dp.setFileDraw ( false ); } public boolean OpenAction () { dp.clearScreen(); if ( pref != null ) resetRef(); curBldgIndex = curFloorIndex = 0; try { tref.getDWGParcel(parcel, updateMode); pref = tref.pref(); pref.parcel(parcel); totalArea = calculateArea.calculateTotalArea(); dp.setTotalArea(totalArea); curBldgIndex = curFloorIndex = 0; isModelBased = false; if ( tref.isDwgModelBased() ) { isModelBased = true; subName = tref.getsubName(); modelName = tref.getModelName(); } dref = null; System.out.println("drawTest.OpenAction marker " + marker + " hostname " + hostname); //dref is not binding 2/23/98 conversion - probably since marker is null //dref = DWGHelper.bind(marker+":TransactionServer",hostname); dref = DWGHelper.bind(":TransactionServer",hostname); if ( (dref.status()) != null) getBldg(0); getFloor(0); getStructure(); dp.rePaintAll(); dp.setFileDraw ( false ); parcelSaved = true; return true; } catch ( dwgtest.TransactionManagerPackage.parcelDoesNotExistException se ) { System.out.println("Error retrieving parcel " + se.toString()); dp.displayMsgDialog("Error","Drawing does not Exist."); return false; } catch ( dwgtest.TransactionManagerPackage.failedConversionException se) { dp.displayMsgDialog("Error","Drawing Failed Conversion, Please Re-Draw"); return false; } catch ( dwgtest.TransactionManagerPackage.parcelLockException se ) { System.out.println("Parcel In Use by Another Client " + se.toString()); dp.displayMsgDialog("Error","Parcel In Use by Another Client "); return false; } catch ( SystemException se ) { System.out.println("Error retrieving parcel " + se.toString()); se.printStackTrace(); dp.displayMsgDialog("Error","Error Retrieving Parcel SystemException"); return false; } catch ( NullPointerException ne) { System.out.println("Error retrieving parcel " + ne.toString()); ne.printStackTrace(); dp.displayMsgDialog("Error","Error Retrieving Parcel NullPointerException"); return false; } } public void mouseClicked ( MouseEvent e ){} public void mouseEntered ( MouseEvent e ){} public void mouseExited ( MouseEvent e ){} public void mousePressed ( MouseEvent e ){} public void mouseReleased ( MouseEvent e ){} public void itemStateChanged ( ItemEvent e ){} public void actionPerformed ( ActionEvent e ){} // The Following Methods are for the drawing process control public boolean createParcel(String parcel, boolean overRide) { // System.out.println("creating pref for " + parcel); String pmarker = null; if ( parcel.charAt(0) == 'M' ) pmarker = parcel; else pmarker = "p" + parcel; System.out.println("DEBUG DrawTest.createParcel() " + pmarker); try { pref = tref.createDWGParcel(parcel, overRide); pref.parcel(parcel); pref.vectorLength(0); //tref.pref(pref); tref.setDWGParcelFunction(pref); } catch ( dwgtest.TransactionManagerPackage.parcelAlreadyExistsException se) { System.out.println("pref " + se.toString()); if ( dp.yesNoDialog("Drawing Already Exists! !", "Demolish Will Create Over Existing Drawing", "Demolish", "Cancel" ) ) { dp.setCursor ( new Cursor ( Cursor.WAIT_CURSOR ) ); controls.statusField.setText("Demolishing..."); if (createParcel(parcel, true)) { controls.statusField.setText("Ready"); dp.setCursor ( new Cursor ( Cursor.DEFAULT_CURSOR ) ); return true; } else { dp.displayMsgDialog("Warning", "Could Not Demolish Parcel: " + parcel); return false; } } else return false; } catch ( dwgtest.TransactionManagerPackage.parcelLockException se) { System.out.println("parcel in use by another Client " + se.toString()); dp.displayMsgDialog("Error","Parcel in use by another Client "); return false; } catch ( SystemException se) { se.printStackTrace(); dp.displayMsgDialog("Error"," SystemException"); return false; } return true; } public void createBldg(String name) { try { if ( pref == null )createParcel(parcel, false); else bref = pref.createDWGBldg(name); bref.vectorLength(0); // reset to 0 floors } catch ( SystemException se) { System.out.println("bref " + se.toString()); dp.displayMsgDialog("Error"," Error Creating Building Object"); } } public boolean deleteBldg(int bldgNumber) { System.out.println("DrawTest.deleteBldg() " + bldgNumber); try { --bldgNumber; pref.deleteDWGBldg(bldgNumber); return true; } catch ( SystemException se) { System.out.println("delete Bldg " + se.toString()); dp.displayMsgDialog("Error"," Error Delete Bldg"); return false; } } public int getLength(dwgtest.DWGObj doref) { int len = -1; try { len = doref.vectorLength(); } catch (SystemException se) { System.out.println("Error Get Length: " + se.toString()); } return len; } public void deleteFloor(int floorNumber) { try { --floorNumber; bref.deleteDWGFloor(floorNumber); SaveAction(false); } catch ( SystemException se) { System.out.println("delete floor " + se.toString()); dp.displayMsgDialog("Error"," Error Delete Floor"); } } public void createFloor(String name) { int len = getLength((DWGObj)bref); if ( fref != null ) dp.clearFloor(); isBasement = false; viewBasement = false; try { dp.clearFloor(); dp.setFloorArea(0.0); if ( bref == null ) createBldg("Main Structure"); fref = (DWGFloor)bref.createDWGFloor(name); name = "Floor " + Integer.toString(len + 1); structureSaved = true; newStructure(name); // Initialize the drawing holder. dp.createFloor(name); dp.clearScreen(); curFloorIndex ++; } catch ( org.omg.CORBA.INV_OBJREF ioe) { System.out.println("fref " + ioe.toString()); dp.displayMsgDialog("Error"," Error Creating Floor Object "); } catch ( SystemException se) { System.out.println("fref " + se.toString()); dp.displayMsgDialog("Error"," Error Create Floor Object"); } } public void deleteBasement(int basementNumber) { try { --basementNumber; bref.deleteDWGBasement(basementNumber); SaveAction(false); } catch ( SystemException se) { System.out.println("delete basement " + se.toString()); dp.displayMsgDialog("Error"," Error Delete basement"); } } public void createBasement(boolean state) { int len; String nameB = null; if ( fref != null ) { len = getLength((DWGObj)bref); // System.out.println("Floor Create: len = " + len); // if ( !structureSaved ) saveStructure("Floor " + Integer.toString(len), true); dp.clearFloor(); } if ( fbref != null ) { // System.out.println("Floor Create: len = " + len); // if ( !updateMode ) saveStructure("Basement ", true); dp.clearFloor(); } isBasement = true; viewBasement = true; try { dp.setFloorArea(0.0); if ( bref == null ) createBldg("Main Structure"); len = bref.nbasements(); String name = "Basement " + Integer.toString(len + 1); fbref = (DWGBasement)bref.createDWGBasement(name); fbref.finished(state); isBasement = true; structureSaved = true; if (state) nameB = "Finished " + name; else nameB = "Unfinished " + name; newStructure(nameB); // Initialize the drawing holder. dp.createFloor(name); dp.clearScreen(); curFloorIndex ++; } catch ( org.omg.CORBA.INV_OBJREF ioe) { System.out.println("fref " + ioe.toString()); dp.displayMsgDialog("Error"," Error Creating Basement "); } catch ( SystemException se) { System.out.println("fref " + se.toString()); dp.displayMsgDialog("Error"," Error Create Basement SystemException "); } } public void newStructure(String name) { //System.out.println("new Structure " + name); dp.lines.removeAllElements(); try { if ( fref == null ) createFloor("Floor"); dref = null; if (isBasement) dref = fbref.createDWG(name); // Initialize the drawing holder. else dref = fref.createDWG(name); // Initialize the drawing holder. dref.valid(true); dp.newStructure(dref.label()); dp.setMarker(_OrbixWeb.Object(dref)._marker()); } catch ( SystemException se) { System.out.println("fref: create DWG " + se.toString()); dp.displayMsgDialog("Error"," fref: create " + name); get_dref(); } if ( parcelSaved ) parcelSaved = false; structureSaved = false; } public void editStructure(int index) { dp.lines.removeAllElements(); String marker = dp.editStructure(index); try { dref = null; dref = DWGHelper.bind(marker+":TransactionServer",hostname); dref.status("EDIT"); dref.valid(true); updateMode = true; } catch ( SystemException se) { System.out.println("Retrieving DWG " + se.toString()); dp.displayMsgDialog("Error"," dref: Edit " + marker); } if ( parcelSaved ) parcelSaved = false; structureSaved = false; } public void get_dref() { //System.out.println("get DWG Structure"); try { dref = fref.dref(); // Initialize the drawing holder. } catch ( SystemException se) { System.out.println("fref: get dref DWG " + se.toString()); dp.displayMsgDialog("Error"," fref: get dref "); } } public int getnFloors() { try { nFloors = bref.vectorLength(); } catch ( SystemException se) { System.out.println("Get N Bldgs : " + se.toString()); dp.displayMsgDialog("Error"," Error: Get N Bldgs : "); }catch(NullPointerException npe){} //System.out.println("Get N Bldgs : Successful " + nFloors); return nFloors; } public int getnBasements() { try { nBasements = bref.nbasements(); } catch ( SystemException se) { System.out.println("Get N Basements : " + se.toString()); dp.displayMsgDialog("Error","Error: Get N Basements "); }catch (NullPointerException npe){} //System.out.println("Get N Basements : Successful " + nFloors); return nBasements; } public String[] getBldgs() { String bldgs[] = null; StringTokenizer bldgStr = null; String strBldgs = null; try { strBldgs = pref.bldgs(); } catch ( SystemException se) { System.out.println("Get Bldgs : " + se.toString()); dp.displayMsgDialog("Error"," Get Bldgs : " + se.toString()); se.printStackTrace(); } //System.out.println("Get Bldgs : Successful"); int i = 0; bldgStr = new StringTokenizer(strBldgs,"|"); bldgs = new String[bldgStr.countTokens()]; while(bldgStr.hasMoreTokens()) { bldgs[i] = new String(bldgStr.nextToken()); //System.out.println("bldgs[" + i + "] = " + bldgs[i]); i++; } return bldgs; } public int getnBldgs() { int n = 0; try { n = pref.vectorLength(); } catch ( SystemException se) { System.out.println("getnBldgs SystemException : " + se.toString()); dp.displayMsgDialog("Error"," Error: Get N Bldgs : "); } catch ( NullPointerException ne) { System.out.println("getnBldgs NullPointerException : " + ne.toString() ); } //System.out.println("Get N Bldgs : Successful"); return n; } public void getBldg(int index) { try { pref = tref.pref(); dp.clearFloor(); dp.clearScreen(); String marker = "b" + (index+1) + parcel + user; bref = DWGBldgHelper.bind(marker + ":TransactionServer", hostname); nFloors = bref.vectorLength(); } catch ( SystemException se) { System.out.println("Get Bldg : " + se.toString()); dp.displayMsgDialog("Error","Error: Get Bldg : " + index); } curBldgIndex = index; } public void getFloor(int index) { isBasement = false; viewBasement = false; try { dp.clearFloor(); dp.clearScreen(); String marker = "f" + (index+1) + "b" + (curBldgIndex+1)+ parcel + user; fref = DWGFloorHelper.bind(marker + ":TransactionServer", hostname); nFloors = fref.vectorLength(); int scale = getScale(); dp.setScale( scale ); double area = calculateArea.calculateFloorArea(marker, scale, isBasement); fref.area(area); //System.out.println("fref.get_area(area) " + fref.get_area()); //System.out.println("getFloor area is " + area); dp.setFloorArea( area ); } catch ( SystemException se) { se.printStackTrace(); System.out.println("Get Floor : " + se.toString()); } curFloorIndex = index; } public void getBasement(int index) { //System.out.println("Retrieving Basement " + index); isBasement = true; viewBasement = true; try { dp.clearFloor(); dp.clearScreen(); String marker = "fb" + (index+1) + "b" + (curBldgIndex+1)+ parcel+ user; fbref = DWGBasementHelper.bind(marker + ":TransactionServer", hostname); nBasements = bref.nbasements(); int scale = getScale(); dp.setScale(scale); double basementArea = calculateArea.calculateFloorArea(marker, scale, isBasement); dp.setFloorArea( basementArea ); } catch ( SystemException se) { System.out.println("Get Basement : " + se.toString()); dp.displayMsgDialog("Error"," Get Basement : " + index); } curFloorIndex = index; } public void setSaved(boolean value) { structureSaved = value; } public void saveStructure(boolean newPage) { if ( structureSaved ) return; dwgtest.DWGPackage.dwgStruct []linearr = null; if ( dp.lines.size() > 0 ) { linearr = new dwgtest.DWGPackage.dwgStruct[dp.lines.size()]; copyVectorToArr(dp.lines, linearr); } try { if ( bref == null ) createBldg("Main Structure"); if ( fref == null ) createFloor("Main"); if ( linearr == null ) { dref.valid(false); return; } DWGStructure dwgs = dp.getStructure(); //System.out.println("Saving " + dwgs.getLabel()); dref.label(dwgs.getLabel()); if ( dwgs.getDeleteStatus()) { fref.deleteDWG(dref); dp.lines.removeAllElements(); } else { if ( dref.status()== "EDIT") { System.out.println("drawtest.saveStructure() marker save " + dwgs.getMarker()); if ( _OrbixWeb.Object(dref)._marker() != dwgs.getMarker()) dref = DWGHelper.bind(dwgs.getMarker() + ":TransactionServer",hostname); dref.status("MOD"); // Define later } else { dref.status("NEW"); // Define later dref.newpage(newPage); // Whether the structure goes on a new page } //This is the culprit... 2/23/99 DS //dref.dwgVector(linearr); dref.setDwgVectorFunction(linearr); double area = dp.getArea(); dref.area(area); dwgtest.DWGObjPackage.point pt = new dwgtest.DWGObjPackage.point(); pt.x = dwgs.getTitlePoint().x; pt.y = dwgs.getTitlePoint().y; dref.setPointFunction(pt); //dref.scale(dp.getScale()); fref.scale(dp.getScale()); } if ( !updateMode ) { if ( isBasement ) { fbref.saveDWG(dref); fbref.area(dp.getFloorArea()); } else { fref.saveDWG(dref); double larea = dp.getFloorArea(); fref.area(larea); } setScale(dp.getScale()); } else { if ( isBasement ) { fbref.area(dp.getFloorArea()); } else { double larea = dp.getFloorArea(); fref.area(larea); } updateMode = false; } structureSaved = true; } catch ( SystemException se ) { se.printStackTrace(); dp.displayMsgDialog("Error", "Error: Saving " ); } } public void getStructure() { DWG dref = null; String m_sortCode = null; try { int len = 0; Vector v = new Vector(); int scale = 0; if ( isBasement ) { m_sortCode = "fb" + (curFloorIndex+1) + "b" + (curBldgIndex+1) + parcel + user; len = fbref.vectorLength(); } else { m_sortCode = "f" + (curFloorIndex+1) + "b" + (curBldgIndex+1) + parcel + user; len = fref.vectorLength(); } if ( scale == 0) scale = getScale(); dwgtest.DWGPackage.dwgStruct[] d = new dwgtest.DWGPackage.dwgStruct[len]; for ( int i = 0; i < len; i++ ) { String dname = "dwg" + (i+1) + m_sortCode; dref = DWGHelper.bind(dname + ":TransactionServer",hostname); d = dref.dwgVector(); dwgtest.DWGObjPackage.point pt = dref.location(); String label = dref.label(); if (isBasement && label.startsWith("Basement")) { boolean finished = fbref.finished(); if (finished) label = "Finished " + label; else label = "Unfinished " + label; } double area = dref.area(); DWGStructure ds = new DWGStructure(label); ds.setScale(scale); if ( (dref.status()).equals("DELETED"))ds.setDeleteStatus(true); ds.setTitlePoint(new Point(pt.x,pt.y)); ds.setMarker(dname); if ( d != null ) { if ( d.length > 0 ) copyArrToVector(v, d); ds.setDetails(v, area); } v.removeAllElements(); dp.addToFloor(ds); } } catch ( SystemException se ) { System.out.println("get Structure " + se.toString()); dp.displayMsgDialog("Error","Error: get Structure " ); se.printStackTrace(); } } public int lastSeparator(Vector v) { int i; for ( i = v.size() - 1; i >= 0; i--) if ( v.elementAt(i) instanceof DWGSeparator ) return i; return 0; } public void copyVectorToArr(Vector v, dwgtest.DWGPackage.dwgStruct[] d) { int dlen = lastSeparator(v); String s; if ( dlen > 0 ) dlen = dlen + 1; for ( int i = dlen; i < v.size(); i++ ) { if ( ! (v.elementAt(i) instanceof DWGSeparator )) { if ( v.elementAt(i) instanceof DWGSymbol ) { Point b = ((DWGDrawingObject)v.elementAt(i)).getBeginning(); int c = (((DWGDrawingObject)v.elementAt(i)).getForeground()).getRGB(); d[i] = new dwgtest.DWGPackage.dwgStruct ("DWGSymbol",Integer.toString(((DWGSymbol)v.elementAt(i)).getStype()), b.x, b.y, -1, -1,1,((DWGSymbol)v.elementAt(i)).properties.description,c); } else { if ( v.elementAt(i) instanceof DWGLine ) s = "DWGLine"; else if ( v.elementAt(i) instanceof DWGArc ) s = "DWGArc"; else if ( v.elementAt(i) instanceof DWGCircle ) s = "DWGCircle"; else if ( v.elementAt(i) instanceof DWGRectangle ) s = "DWGRectangle"; else s = "Tester"; Point b = ((DWGDrawingObject)v.elementAt(i)).getBeginning(); Point e = ((DWGDrawingObject)v.elementAt(i)).getEnd(); int c = (((DWGDrawingObject)v.elementAt(i)).getForeground()).getRGB(); // System.out.println("Inserting " + s); d[i] = new dwgtest.DWGPackage.dwgStruct(s,"Label" + i, b.x, b.y, e.x, e.y, -1,"hello",c); // System.out.println("Element " + i + ": " + v.elementAt(i)); // System.out.println("Dbuffer " + i + ": " + d.buffer[i]); } } // System.out.println("den = " + d.length + " vsize " + v.size() + " dlen = " + dlen); } } public void copyArrToVector(Vector v, dwgtest.DWGPackage.dwgStruct[] d) { for ( int i = 0; i < d.length; i++ ) { // System.out.println("Class " + d.buffer[i].classname ); String classname = new String((d[i].classname).trim()); if ( classname.equals("DWGLine")) { DWGLine dl = new DWGLine( d[i].begin_x, d[i].begin_y, d[i].end_x, d[i].end_y ); dl.setForeground(new Color(d[i].color)); dl.setDrawPanelTarget(dpt); dl.addItemListener(dpt); v.addElement(dl); } if ( classname.equals("DWGArc")) { DWGArc dl = new DWGArc ( d[i].begin_x, d[i].begin_y, d[i].end_x, d[i].end_y ); dl.setForeground(new Color(d[i].color)); dl.setDrawPanelTarget(dpt); dl.addItemListener(dpt); v.addElement(dl); } if ( classname.equals("DWGRectangle")) { DWGRectangle dl = new DWGRectangle( d[i].begin_x, d[i].begin_y, d[i].end_x, d[i].end_y ); dl.setForeground(new Color(d[i].color)); dl.setDrawPanelTarget(dpt); dl.addItemListener(dpt); v.addElement(dl); } if ( classname.equals("DWGCircle")) { DWGCircle dl = new DWGCircle( d[i].begin_x, d[i].begin_y, d[i].end_x, d[i].end_y ); dl.setForeground(new Color(d[i].color)); dl.setDrawPanelTarget(dpt); dl.addItemListener(dpt); v.addElement(dl); } if ( classname.equals("DWGSymbol")) { DWGSymbol dl = new DWGSymbol( Integer.parseInt((d[i].label).trim()), d[i].begin_x, d[i].begin_y, d[i].desc ); dl.setForeground(new Color(d[i].color)); dl.setDrawPanelTarget(dpt); dl.addItemListener(dpt); v.addElement(dl); } if ( classname.equals("noteText")) { // v.addElement(new noteText( d.buffer[i].begin_x, d.buffer[i].begin_y, // d.buffer[i].end_x, d.buffer[i].end_y )); } } } public String getUserName() { return user; } public String getParcelNumber() { return this.parcel; } public void set_labelLoc(Point p) { labelLoc = p; } public Point get_labelLoc() { return labelLoc; } public void resetRef() { bref = null; fref = null; dispose(); pref = null; System.gc(); } public void setScale(int scale) { try { if ( isBasement ) fbref.scale(scale); else fref.scale(scale); } catch(SystemException se) { se.printStackTrace(); } } public int getScale() { try { if ( isBasement ) return fbref.scale(); else return fref.scale(); } catch(SystemException se){se.printStackTrace();} return 4; } // dispose of the created obj refs for this parcel.... public void dispose() { try { tref.dispose(); }catch (SystemException se){se.printStackTrace();} } // Models processing public String[] getSubdivisons(String key) { String subDivisions[] = null; String modelStr = null; StringTokenizer st = null; try { modelStr = tref.get_subdivs(key); } catch ( dwgtest.TransactionManagerPackage.InvalidQueryException iqe ) { dp.displayMsgDialog("Error", iqe.reason ); } catch ( SystemException se ) { dp.displayMsgDialog("Error"," Error retrieving subdiv list " ); System.out.println(se.toString()); se.printStackTrace(); } int i = 0; st = new StringTokenizer(modelStr,"|"); subDivisions = new String[st.countTokens()]; while(st.hasMoreTokens()) { subDivisions[i] = new String(st.nextToken()); //System.out.println("bldgs[" + i + "] = " + bldgs[i]); i++; } return subDivisions; } public String[] getModels(String key) { String models[] = null; String modelStr = null; StringTokenizer st = null; try { modelStr = tref.get_models(key); } catch ( dwgtest.TransactionManagerPackage.InvalidQueryException iqe ) { dp.displayMsgDialog("Error", iqe.reason ); } catch ( SystemException se ) { dp.displayMsgDialog("Error"," Error retrieving models for subdiv " + key ); } int i = 0; st = new StringTokenizer(modelStr,"|"); models = new String[st.countTokens()]; while(st.hasMoreTokens()) { models[i] = new String(st.nextToken()); //System.out.println("bldgs[" + i + "] = " + bldgs[i]); i++; } return models; } public int transfer(String fromParcel, String toParcel, boolean overWrite) { try { return tref.transfer(fromParcel, toParcel, overWrite); }catch (SystemException se) { System.out.println(se); return IO_ERROR; } } public String copyParcel(String fromParcel, String toParcelList) { try { return tref.copyParcel(fromParcel, toParcelList); }catch(SystemException se) { System.out.println(se); return ("Failed ! "); } } public boolean saveAsParcel(String sourceDrawing, String book, String map, String item) { try { return tref.saveAsParcel(sourceDrawing, book, map, item); }catch (SystemException se) { se.printStackTrace(); return false; } } public boolean saveAsModel(String sourceDrawing, String subName, String model) { try { return tref.saveAsModel(sourceDrawing, subName, model); }catch (SystemException se) { System.out.println(se); return false; } } public boolean isModelBased() { return isModelBased; } public String getSubName() { return subName; } public String getModelName() { return modelName; } //This is used to the the file for a model or modelbased dwg public String getModelFile(String subName, String model) { String srcFile = null; try { srcFile = tref.getModelID(subName,modelName,false); } catch(SystemException se){se.printStackTrace();} return srcFile; } public long getAvailableMemory() { return tref.getAvailableMemory(); } public String[] getClients() { String clients[] = null; String clientStr = null; StringTokenizer st = null; clientStr = tref.getClients(); int i = 0; st = new StringTokenizer(clientStr,"|"); clients = new String[st.countTokens()]; while(st.hasMoreTokens()) { clients[i] = new String(st.nextToken()); i++; } return clients; } public Vector getLines() { return dp.lines; } }


Back to Portfolio