update dev300-m58
[ooovba.git] / soldep / source / soldep.cxx
blob3dc9f34738919164e006ca62e6efda84e8e1ae0d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: soldep.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 //TBD: ToolBox handling prjview/back
32 #include <osl/file.hxx>
33 #include <rtl/ustring.hxx>
34 #include <tools/debug.hxx>
35 #include <bootstrp/sstring.hxx>
36 #include <svtools/filedlg.hxx>
37 #include <tools/iparser.hxx>
38 #include <tools/geninfo.hxx>
39 #include <vcl/gdimtf.hxx>
40 #include <vcl/bitmap.hxx>
41 #include <appdef.hxx>
42 #include "time.h"
43 #include <soldep/depper.hxx>
44 #include <soldep/soldep.hxx>
45 #include <soldep/soldlg.hxx>
46 #include <soldep/XmlBuildList.hxx>
47 #include "dtsodcmp.hrc"
49 IMPLEMENT_HASHTABLE_OWNER( SolIdMapper, ByteString, ULONG* );
50 //IMPLEMENT_HASHTABLE_OWNER( PrjIdMapper, ByteString, ULONG* );
51 #define EVENT_RESIZE 0x00000001
52 #define MIN(a,b) (a)<(b)?(a):(b)
53 #define MAX(a,b) (a)>(b)?(a):(b)
56 //ByteString sDelimiterLine("#==========================================================================");
60 // class SolDep
63 /*****************************************************************************/
64 SolDep::SolDep( Window* pBaseWindow )
65 /*****************************************************************************/
66 : Depper( pBaseWindow ),
67 mbBServer(FALSE),
68 mpTravellerList( NULL ),
69 mbIsHide( FALSE ),
70 mpXmlBuildList (NULL)
73 ByteString sModulPath ("."); // wo soll das Perlmodul stehen???
74 try
76 mpXmlBuildList = new XmlBuildList (sModulPath);
78 catch (XmlBuildListException& Exception) {
79 const char* Message = Exception.getMessage();
82 mnSolWinCount = 0;
83 mnSolLastId = 0;
84 // mpPrjIdMapper = new SolIdMapper( 63997 );
85 maTaskBarFrame.EnableAlwaysOnTop();
86 maTaskBarFrame.Show();
87 maToolBox.SetPosSizePixel( Point( 0,0 ), Size( 1100,35 ));
88 maToolBox.SetSelectHdl( LINK ( this, SolDep, ToolSelect ));
89 maToolBox.Show();
91 mpBaseWin->AddChildEventListener( LINK( this, SolDep, ChildWindowEventListener ));
93 // Kontext-Menue (gehört zu soldep.cxx)
94 InitContextMenueMainWnd();
95 InitContextMenuePrjViewWnd( mpBasePrjWin );
98 /*****************************************************************************/
99 SolDep::~SolDep()
100 /*****************************************************************************/
102 mpBaseWin->RemoveChildEventListener( LINK( this, SolDep, ChildWindowEventListener ) );
103 delete mpSolIdMapper;
104 delete mpStarWriter;
105 delete mpStandLst;
106 if (mpXmlBuildList)
107 delete mpXmlBuildList;
110 /*****************************************************************************/
111 void SolDep::Init()
112 /*****************************************************************************/
114 InformationParser aParser;
115 String sStandLst( GetDefStandList(), RTL_TEXTENCODING_ASCII_US );
116 mpStandLst = aParser.Execute( sStandLst );
117 ByteString aUpdater( getenv("UPDATER") );
118 if ( mpStandLst && (aUpdater == "YES") ) {
119 if ( GetVersion() )
120 ReadSource( TRUE );
121 } else
123 ReadSource(); // if stand.lst isn't available
127 /*****************************************************************************/
128 void SolDep::Init( ByteString &rVersion, GenericInformationList *pVersionList )
129 /*****************************************************************************/
131 // Interface for bs
132 mbBServer=TRUE;
133 if ( pVersionList )
134 mpStandLst = new GenericInformationList( *pVersionList );
135 else {
136 InformationParser aParser;
137 String sStandLst( GetDefStandList(), RTL_TEXTENCODING_ASCII_US );
138 mpStandLst = aParser.Execute( sStandLst );
140 if ( mpStandLst ) {
141 msVersionMajor = ByteString( rVersion );
142 ReadSource(TRUE); //call from build server set UPDATER to TRUE
146 /*****************************************************************************/
147 IMPL_LINK( SolDep, ChildWindowEventListener, VclSimpleEvent*, pEvent )
148 /*****************************************************************************/
150 if ( pEvent && pEvent->ISA( VclWindowEvent ) )
152 ProcessChildWindowEvent( *static_cast< VclWindowEvent* >( pEvent ) );
154 return 0;
158 /*****************************************************************************/
159 void SolDep::ProcessChildWindowEvent( const VclWindowEvent& _rVclWindowEvent )
160 /*****************************************************************************/
162 Window* pChildWin = _rVclWindowEvent.GetWindow();
163 // Window* pParentWin = pChildWin->GetParent();
164 //Resize();
165 if ( isAlive() )
167 ULONG id = _rVclWindowEvent.GetId();
168 switch ( id )
170 case VCLEVENT_USER_MOUSEBUTTON_DOWN:
172 ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
173 if( pObjWin )
175 // handle mouse click on ObjectWin object
176 ObjectWin* pWin = (ObjectWin*) pChildWin;
177 //GetObjectList()->ResetSelectedObject();
178 if (IsHideMode()) // simple mouse click left
180 pWin->CaptureMouse();
181 pWin->SetMarkMode( MARKMODE_SELECTED );
182 pWin->MarkNeeded();
183 pWin->MarkDepending();
184 pWin->Invalidate();
185 } else
187 pWin->LoseFocus();
188 pWin->SetMarkMode( MARKMODE_SELECTED );
189 pWin->UnsetMarkMode( MARKMODE_ACTIVATED );
190 pWin->MarkNeeded( TRUE );
191 pWin->MarkDepending( TRUE );
196 break;
197 case VCLEVENT_USER_MOUSEBUTTON_DOWN_ALT:
199 ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
200 if( pObjWin )
202 ObjectWin* pWin = (ObjectWin*) pChildWin;
203 MarkObjects( pWin );
206 break;
207 case VCLEVENT_USER_MOUSEBUTTON_DOWN_DBLCLICK:
209 ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
210 if( pObjWin )
212 if (IsHideMode()) ToggleHideDependency();
213 ByteString text = ((ObjectWin*) pChildWin)->GetBodyText();
214 ViewContent(text);
217 break;
218 case VCLEVENT_USER_MOUSEBUTTON_UP_SHFT:
220 ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
221 if( pObjWin )
223 ObjectWin* pWin = (ObjectWin*) pChildWin;
224 GetDepWin()->NewConnector( pWin );
227 break;
228 case VCLEVENT_USER_MOUSEBUTTON_UP:
230 ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
231 if( pObjWin )
233 ObjectWin* pWin = (ObjectWin*) pChildWin;
234 pWin->ReleaseMouse();
235 pWin->SetMarkMode(MARKMODE_SELECTED);
236 GetDepWin()->Invalidate();
239 break;
240 } // switch
241 } // if isAlive
242 //fprintf(stdout,"BLA::Resize: %d\n",pChildWin);
245 /*****************************************************************************/
246 IMPL_LINK( SolDep, ToolSelect, SoldepToolBox* , pBox)
247 /*****************************************************************************/
249 USHORT nItemId = pBox->GetCurItemId();
250 switch ( nItemId )
252 case TID_SOLDEP_FIND:
253 FindProject();
254 break;
255 case TID_SOLDEP_CREATEMETA :
257 VirtualDevice aVDev;
258 aVDev.SetMapMode( MAP_100TH_MM );
259 GDIMetaFile aMtf;
260 aVDev.EnableOutput( FALSE );
261 aMtf.Record( &aVDev );
263 aVDev.SetLineColor( Color( COL_BLACK ) );
264 aVDev.SetTextAlign( ALIGN_TOP );
266 Size aSize( GetDepWin()->GetOutputSizePixel() );
267 long nXMin = aSize.Width();
268 long nXMax = 0;
269 long nYMax = 0;
270 long nYMin = aSize.Height();
272 for ( USHORT i=0; i<mpObjectList->Count(); i++ )
274 Point aPoint = mpObjectList->GetObject(i)->GetPosPixel();
275 Size aSize = mpObjectList->GetObject(i)->GetSizePixel();
276 nXMin = MIN( aPoint.X(), nXMin );
277 nXMax = MAX( aPoint.X() + aSize.Width(), nXMax );
278 nYMin = MIN( aPoint.Y(), nYMin );
279 nYMax = MAX( aPoint.Y() + aSize.Height(), nYMax );
282 Point aOffset( nXMin, nYMin );
283 aOffset = aVDev.PixelToLogic( aOffset );
285 GetDepWin()->DrawOutput( &aVDev, aOffset );
286 for ( USHORT i=0; i<mpObjectList->Count(); i++ )
287 if ( mpObjectList->GetObject(i)->IsVisible() )
288 mpObjectList->GetObject(i)->DrawOutput( &aVDev, aOffset );
290 aMtf.Stop();
291 aMtf.WindStart();
292 aMtf.SetPrefMapMode( aVDev.GetMapMode() );
293 Size aDevSize( nXMax-nXMin + 10, nYMax-nYMin + 10);
294 aDevSize = aVDev.PixelToLogic( aDevSize );
295 aMtf.SetPrefSize( aDevSize );
296 SvFileStream aStream( String::CreateFromAscii("d:\\out.svm"), STREAM_STD_READWRITE );
297 aMtf.Write( aStream );
298 break;
300 case TID_SOLDEP_HIDE_INDEPENDEND:
302 ToggleHideDependency();
303 for ( USHORT i=0; i<mpObjectList->Count(); i++ )
304 mpObjectList->GetObject(i)->SetViewMask(!mbIsHide);
306 maToolBox.CheckItem(TID_SOLDEP_HIDE_INDEPENDEND, IsHideMode());
307 GetDepWin()->Invalidate(); //repaint Main-View
309 break;
310 case TID_SOLDEP_SELECT_WORKSPACE:
311 if (mpStandLst)
313 if (GetVersion()) // Version dialog box
315 delete mpSolIdMapper;
316 delete mpStarWriter;
317 mpObjectList->ClearAndDelete();
318 ReadSource(TRUE);
321 break;
322 case TID_SOLDEP_BACK:
323 maToolBox.HideItem(TID_SOLDEP_BACK);
324 maToolBox.ShowItem(TID_SOLDEP_SELECT_WORKSPACE); //disabled for prj view (doubleclick ObjWin)
325 maToolBox.ShowItem(TID_SOLDEP_HIDE_INDEPENDEND); //disabled for prj view (doubleclick ObjWin)
326 maToolBox.ShowItem(TID_SOLDEP_FIND); //disabled for prj view (doubleclick ObjWin)
327 maToolBox.Resize();
328 TogglePrjViewStatus();
329 break;
331 return 0;
334 /*****************************************************************************/
335 void SolDep::ToggleHideDependency()
336 /*****************************************************************************/
338 mbIsHide = !mbIsHide;
339 maToolBox.CheckItem(TID_SOLDEP_HIDE_INDEPENDEND, IsHideMode());
340 ObjectWin* pWin = GetObjectList()->GetObject( 0 );
341 pWin->ToggleHideMode();
344 /*****************************************************************************/
345 BOOL SolDep::GetVersion()
346 /*****************************************************************************/
348 SolSelectVersionDlg aVersionDlg( GetDepWin(), mpStandLst );
349 if ( aVersionDlg.Execute() == RET_OK ) {
350 msVersionMajor = aVersionDlg.GetVersionMajor();
351 msVersionMinor = aVersionDlg.GetVersionMinor();
352 return TRUE;
354 return FALSE;
357 void SolDep::InitContextMenueMainWnd()
359 InitContextMenuePrjViewWnd( mpBaseWin );
360 return; // Disable not actually supported items
362 mpBaseWin->mpPopup->InsertItem( DEPPOPUP_AUTOARRANGE, String::CreateFromAscii("Autoarrange")) ;
363 mpBaseWin->mpPopup->InsertSeparator();
364 mpBaseWin->mpPopup->InsertItem( DEPPOPUP_READ_SOURCE, String::CreateFromAscii("Revert all changes") );
365 mpBaseWin->mpPopup->InsertSeparator();
366 mpBaseWin->mpPopup->InsertItem( DEPPOPUP_OPEN_SOURCE, String::CreateFromAscii("Open") );
367 mpBaseWin->mpPopup->InsertItem( DEPPOPUP_WRITE_SOURCE, String::CreateFromAscii("Save") );
370 void SolDep::InitContextMenuePrjViewWnd(DepWin* pBaseWin )
372 // temp. disabled pBaseWin->mpPopup->InsertItem( DEPPOPUP_NEW, String::CreateFromAscii("New object") );
373 pBaseWin->mpPopup->InsertItem( DEPPOPUP_ZOOMIN, String::CreateFromAscii("Zoom in") );
374 pBaseWin->mpPopup->InsertItem( DEPPOPUP_ZOOMOUT, String::CreateFromAscii("Zoom out") );
375 pBaseWin->mpPopup->InsertSeparator();
376 // temp disabled pBaseWin->mpPopup->InsertItem( DEPPOPUP_CLEAR, String::CreateFromAscii("Clear") );
377 pBaseWin->mpPopup->InsertItem( DEPPOPUP_SHOW_TOOLBOX, String::CreateFromAscii("Show Toolbox") );
380 /*****************************************************************************/
381 ObjectWin *SolDep::RemoveObject( USHORT nId, BOOL bDelete )
382 /*****************************************************************************/
384 Prj* pPrj;
386 //hshtable auf stand halten
387 ObjectWin* pWin = RemoveObjectFromList( mpObjectList, mnSolWinCount, nId, FALSE );
388 if ( pWin )
390 ByteString aBodyText( pWin->GetBodyText() );
391 if( (pPrj = mpStarWriter->GetPrj( aBodyText )) )
393 mpStarWriter->Remove( pPrj );
394 //cleanup ist teuer...
395 mpStarWriter->CleanUp();
396 delete pPrj;
398 else
399 DBG_ASSERT( FALSE, "project not found - write" );
401 mpSolIdMapper->Delete( aBodyText );
402 if ( bDelete )
403 delete pWin;
404 return pWin;
406 else
407 return NULL;
410 /*****************************************************************************/
411 ULONG SolDep::AddObject( ByteString& rBodyText, BOOL bInteract )
412 /*****************************************************************************/
414 ULONG nObjectId;
415 if ( bInteract )
417 nObjectId = HandleNewPrjDialog( rBodyText );
419 else
421 //hashtable auf stand halten
422 MyHashObject* pHObject;
423 nObjectId = AddObjectToList( mpBaseWin, mpObjectList, mnSolLastId, mnSolWinCount, rBodyText, FALSE );
424 pHObject = new MyHashObject( nObjectId, ObjIdToPtr(mpObjectList, nObjectId ));
425 mpSolIdMapper->Insert( rBodyText, pHObject );
427 return nObjectId;
430 /*****************************************************************************/
431 ULONG SolDep::AddPrjObject( ByteString& rBodyText, BOOL bInteract )
432 /*****************************************************************************/
434 ULONG nObjectId;
435 if ( bInteract )
437 nObjectId = HandleNewDirectoryDialog( rBodyText );
439 else
441 //hshtable auf stand halten
442 MyHashObject* pHObject;
443 nObjectId = AddObjectToList( mpBasePrjWin, mpObjectPrjList, mnPrjLastId, mnPrjWinCount, rBodyText );
444 pHObject = new MyHashObject( nObjectId, ObjIdToPtr( mpObjectPrjList, nObjectId ));
445 mpPrjIdMapper->Insert( rBodyText, pHObject ); // mpPrjIdMapper
447 return nObjectId;
450 /*****************************************************************************/
451 USHORT SolDep::AddConnector( ObjectWin* pStartWin, ObjectWin* pEndWin )
452 /*****************************************************************************/
454 // DBG_ASSERT( FALSE , "not yet" );
455 ByteString sEndName = pEndWin->GetBodyText();
456 ByteString sStartName = pStartWin->GetBodyText();
458 Prj* pPrj = mpStarWriter->GetPrj( sEndName );
459 if ( pPrj )
461 pPrj->AddDependencies( sStartName );
462 return AddConnectorToObjects( pStartWin, pEndWin );
464 else
466 DBG_ASSERT( FALSE , "non existing Project" );
467 return 1;
471 /*****************************************************************************/
472 USHORT SolDep::RemoveConnector( ObjectWin* pStartWin, ObjectWin* pEndWin )
473 /*****************************************************************************/
475 SByteStringList* pPrjDeps = NULL;
476 ByteString sEndName = pEndWin->GetBodyText();
477 ByteString sStartName = pStartWin->GetBodyText();
479 Prj* pPrj = mpStarWriter->GetPrj( sEndName );
480 pPrjDeps = pPrj->GetDependencies( FALSE );
481 if ( pPrjDeps )
483 ByteString* pString;
484 ULONG nPrjDepsCount = pPrjDeps->Count();
485 for ( ULONG j = nPrjDepsCount; j > 0; j-- )
487 pString = pPrjDeps->GetObject( j - 1 );
488 if ( pString->GetToken( 0, '.') == sStartName )
489 pPrjDeps->Remove( pString );
493 return RemoveConnectorFromObjects( pStartWin, pEndWin );
496 /*****************************************************************************/
497 void SolDep::RemoveAllObjects( ObjectList* pObjLst )
498 /*****************************************************************************/
501 Depper::RemoveAllObjects( pObjLst );
503 if ( mpSolIdMapper )
505 delete mpSolIdMapper;
506 mpSolIdMapper = NULL;
508 if ( mpStarWriter )
510 delete mpStarWriter;
511 mpStarWriter = NULL;
515 /*****************************************************************************/
516 ULONG SolDep::GetStart(SolIdMapper* pIdMapper, ObjectList* pObjList)
517 /*****************************************************************************/
519 // DBG_ASSERT( FALSE , "soldep" );
520 MyHashObject* pHObject = pIdMapper->Find( "null" );//null_project
522 if ( !pHObject ) {
523 ByteString sNullPrj = "null";//null_project
524 ULONG nObjectId = AddObject( sNullPrj, FALSE );
525 ObjIdToPtr( pObjList, nObjectId )->SetViewMask( 1 );
526 return nObjectId;
529 return pHObject->GetId();
532 /*****************************************************************************/
533 ULONG SolDep::GetStartPrj(SolIdMapper* pIdMapper, ObjectList* pObjList)
534 /*****************************************************************************/
536 // DBG_ASSERT( FALSE , "prjdep" );
537 MyHashObject* pHObject = mpPrjIdMapper->Find( ByteString( "null" ) ); //null_dir
538 if ( !pHObject )
540 ByteString bsNull("null");
541 ULONG nObjectId = AddPrjObject( bsNull, FALSE); //null_dir
542 return nObjectId;
544 else
545 return pHObject->GetId();
548 /*****************************************************************************/
549 USHORT SolDep::OpenSource()
550 /*****************************************************************************/
552 if ( mpStandLst ) {
553 if ( GetVersion())
554 return ReadSource();
556 return 0;
559 /*****************************************************************************/
560 USHORT SolDep::ReadSource(BOOL bUpdater)
561 /*****************************************************************************/
563 mpBaseWin->EnablePaint( FALSE );
564 mpBaseWin->Hide();
565 ULONG nObjectId, nHashedId;
566 ULONG i;
567 MyHashObject* pHObject;
568 ByteString* pStr;
569 ObjectWin *pStartWin, *pEndWin;
571 mpSolIdMapper = new SolIdMapper( 63997 );
572 if (mpStandLst && bUpdater)
574 mpStarWriter = new StarWriter( mpXmlBuildList, mpStandLst, msVersionMajor, msVersionMinor, TRUE );
575 } else
577 SolarFileList* pSolarFileList;
578 pSolarFileList = GetPrjListFromDir();
579 mpStarWriter = new StarWriter( mpXmlBuildList, pSolarFileList, TRUE );
581 ByteString sTitle( SOLDEPL_NAME );
582 if ( mpStarWriter->GetMode() == STAR_MODE_SINGLE_PARSE ) {
583 sTitle += ByteString( " - mode: single file [" );
584 sTitle += (ByteString) mpStarWriter->GetName();
585 sTitle += ByteString( "]" );
587 else if ( mpStarWriter->GetMode() == STAR_MODE_MULTIPLE_PARSE ) {
588 sTitle += ByteString( " - mode: multiple files [" );
589 sTitle += ByteString( "]" );
591 SetTitle( String( sTitle, RTL_TEXTENCODING_UTF8) );
593 ULONG nCount = mpStarWriter->Count();
594 for ( i=0; i<nCount; i++ )
596 Prj *pPrj = mpStarWriter->GetObject(i);
597 ByteString sPrjName = pPrj->GetProjectName();
598 nObjectId = AddObject( sPrjName, FALSE );
599 ObjIdToPtr( mpObjectList, nObjectId )->SetViewMask( 1 );
601 for ( i=0; i<nCount; i++ )
603 Prj *pPrj = mpStarWriter->GetObject(i);
604 SByteStringList *pLst = pPrj->GetDependencies( FALSE );
605 if ( pLst )
607 ULONG nDepCount = pLst->Count();
608 for ( ULONG m=0; m<nDepCount; m++)
610 pStr = pLst->GetObject(m);
611 pHObject = mpSolIdMapper->Find( *pStr );
612 /*if ( !pHObject )
614 // create new prj
615 Prj *pNewPrj = new Prj( *pStr );
616 ByteString sPrjName = pNewPrj->GetProjectName();
617 nObjectId = AddObject( sPrjName, FALSE );
618 pHObject = mpSolIdMapper->Find( *pStr );
619 ObjIdToPtr( mpObjectList, nObjectId )->SetViewMask( 2 );
622 if ( pHObject )
624 nHashedId = pHObject->GetId();
625 ByteString sF_Os2 = pPrj->GetProjectName();
626 pStr = &sF_Os2;
627 pHObject = mpSolIdMapper->Find( *pStr );
628 nObjectId = pHObject->GetId();
629 pStartWin = ObjIdToPtr( mpObjectList, nHashedId );
630 pEndWin = ObjIdToPtr( mpObjectList, nObjectId );
631 AddConnectorToObjects( pStartWin, pEndWin );
636 if (!IsPrjView())
638 AutoArrange( mpSolIdMapper, mpObjectList, GetStart(mpSolIdMapper,mpObjectList), 0, GetStart(mpSolIdMapper,mpObjectList) );
639 GetDepWin()->EnablePaint( TRUE );
641 return 0;
644 SolarFileList* SolDep::GetPrjListFromDir()
646 SolarFileList* pSolarFileList = new SolarFileList();
647 String sPrjDir( String::CreateFromAscii( "prj" ));
648 String sBuildLst( String::CreateFromAscii( "build.lst" ));
649 DirEntry aCurrent( getenv( SOURCEROOT ) );
651 aCurrent.ToAbs();
652 Dir aDir( aCurrent, FSYS_KIND_DIR );
654 USHORT nEntries = aDir.Count();
655 if( nEntries )
657 UniStringList aSortDirList;
658 for ( USHORT n = 0; n < nEntries; n++ )
660 DirEntry& rEntry = aDir[n];
661 UniString aName( rEntry.GetName() );
662 if( aName.Len() && ( aName.GetChar(0) != '.' ) && rEntry.Exists() )
664 rEntry += DirEntry( sPrjDir );
665 rEntry += DirEntry( sBuildLst );
666 if (rEntry.Exists())
668 pSolarFileList->Insert( new String( rEntry.GetFull() ), LIST_APPEND );
669 ByteString aName_dbg(rEntry.GetFull(),RTL_TEXTENCODING_UTF8);
670 fprintf(stdout, "bla:%s\n", aName_dbg.GetBuffer());
675 if ( !pSolarFileList->Count() )
677 //is empty!! TBD
678 delete pSolarFileList;
679 return NULL;
681 return pSolarFileList;
684 /*****************************************************************************/
685 USHORT SolDep::WriteSource()
686 /*****************************************************************************/
688 /* zur Sicherheit deaktiviert
689 USHORT nMode = mpStarWriter->GetMode();
690 if ( nMode == STAR_MODE_SINGLE_PARSE ) {
691 ByteString sFileName = mpStarWriter->GetName();
692 if ( sFileName.Len()) {
693 mpStarWriter->Write( String( sFileName, RTL_TEXTENCODING_UTF8) );
694 mpStarWriter->RemoveProject( ByteString( "null")); //null_project
697 else if ( nMode == STAR_MODE_MULTIPLE_PARSE ) {
698 // *OBO*
699 //String sRoot = mpStarWriter->GetSourceRoot();
700 //nicht mehr unterstützt mpStarWriter->GetSourceRoot()
701 ByteString sFileName = mpStarWriter->GetName();
702 DirEntry aEntry( sFileName );
703 aEntry.ToAbs();
704 aEntry = aEntry.GetPath().GetPath().GetPath();
705 String sRoot = aEntry.GetFull();
707 if ( sRoot.Len()) {
708 mpStarWriter->RemoveProject( ByteString( "null")); //null_project
709 mpStarWriter->WriteMultiple( sRoot );
713 return 1;
716 USHORT SolDep::Load( const ByteString& rFileName )
718 // moved from depper class
719 DBG_ASSERT( FALSE , "you are dead!" );
720 SvFileStream aInFile( String( rFileName, RTL_TEXTENCODING_UTF8 ), STREAM_READ );
721 depper_head dh;
722 ULONG i;
723 ULONG nLoadOffs = mnSolLastId; //or Prj??
724 ObjectWin* pNewWin;
725 aInFile.Read( &dh, sizeof( dh ));
727 ULONG nObjCount = dh.nObjectCount;
728 ULONG nCnctrCount = dh.nCnctrCount;
730 for ( i=0; i < nObjCount ; i++ )
732 ObjectWin* pWin = new ObjectWin( mpBaseWin, WB_BORDER );
733 pWin->Load( aInFile );
734 pNewWin = ObjIdToPtr( mpObjectList, AddObjectToList( mpBaseWin, mpObjectList, mnSolLastId, mnSolWinCount, pWin->GetBodyText(), FALSE ));
735 pNewWin->SetId( nLoadOffs + pWin->GetId());
736 pNewWin->SetPosPixel( pWin->GetPosPixel());
737 pNewWin->SetSizePixel( pWin->GetSizePixel());
740 ULONG nStartId;
741 ULONG nEndId;
742 // ueber addconnector fuehren!
743 for ( i=0; i < nCnctrCount ; i++ )
745 Connector* pCon = new Connector( mpBaseWin, WB_NOBORDER );
746 pCon->Load( aInFile );
748 nStartId = nLoadOffs + pCon->GetStartId();
749 nEndId = nLoadOffs + pCon->GetEndId();
751 ObjectWin* pStartWin = ObjIdToPtr( mpObjectList, nStartId );
752 ObjectWin* pEndWin = ObjIdToPtr( mpObjectList, nEndId );
754 pCon->Initialize( pStartWin, pEndWin );
758 return 0;
761 /*****************************************************************************/
762 BOOL SolDep::ViewContent( ByteString& rObjectName )
763 /*****************************************************************************/
765 mpFocusWin = NULL;
766 SetPrjViewStatus(TRUE);
768 for ( ULONG i = 0; i < mpObjectList->Count() && !mpFocusWin; i++ )
769 if ( mpObjectList->GetObject( i )->HasFocus())
770 mpFocusWin = mpObjectList->GetObject( i );
771 //HideObjectsAndConnections( mpObjectList );
772 mpProcessWin->Resize();
773 GetDepWin()->Show();
774 return InitPrj( rObjectName );
777 /*****************************************************************************/
778 BOOL SolDep::InitPrj( ByteString& rListName )
779 /*****************************************************************************/
781 ULONG nObjectId, nHashedId;
782 ULONG i, j;
783 MyHashObject* pHObject;
784 ByteString *pDepName;
785 ByteString *pFlagName;
786 Prj* pPrj;
787 ObjectWin *pStartWin, *pEndWin;
788 maToolBox.HideItem(TID_SOLDEP_SELECT_WORKSPACE);
789 maToolBox.HideItem(TID_SOLDEP_HIDE_INDEPENDEND);
790 maToolBox.HideItem(TID_SOLDEP_FIND);
791 maToolBox.ShowItem(TID_SOLDEP_BACK);
792 maToolBox.Invalidate();
794 //clean up
795 mpObjectPrjList->ClearAndDelete();
796 GetDepWin()->ClearConnectorList();
797 if (mpPrjIdMapper) delete mpPrjIdMapper;
798 mpPrjIdMapper = new SolIdMapper( 63997 ); //generate clean mapper
799 mnPrjWinCount = 0;
800 mnPrjLastId = 0;
802 ULONG nCount = mpStarWriter->Count();
803 GetDepWin()->EnablePaint( FALSE );
804 Point aPnt = GetGraphWin()->GetPosPixel();
805 Size aSize = GetGraphWin()->GetSizePixel();
807 GetGraphWin()->SetPosSizePixel( aPnt, aSize ); // Hier wird das Window gesetzt
809 BOOL bReturn = FALSE;
811 for ( i=0; i<nCount; i++ )
813 // pPrj->GetProjectName() returns the name of
814 // the project e.g. svtools
815 pPrj = mpStarWriter->GetObject(i);
816 ByteString sPrjName = pPrj->GetProjectName();
817 if ( sPrjName == rListName )
819 bReturn = TRUE;
821 mpPrj = mpStarWriter->GetObject(i);
822 ULONG nDirCount = mpPrj->Count();
823 for ( j=0; j<nDirCount; j++ )
825 CommandData *pData = mpPrj->GetObject(j);
826 fprintf( stdout, "\tProjectDir : %s\n",
827 pData->GetLogFile().GetBuffer());
828 // pData->GetLogFile() contains internal project IDs
829 // e.g. st_mkout etc.
830 if ( pData->GetLogFile() != "" )
832 ByteString sItem = pData->GetLogFile();
833 nObjectId = AddPrjObject( sItem, FALSE);
834 // there may be faster ways......
835 ObjectWin *pWin = ObjIdToPtr( mpObjectPrjList, nObjectId );
836 pWin->SetViewMask( 0x0001 );
837 // pData->GetPath() contains internal project directories
838 // e.g. svtools/inc etc.
839 ByteString sPath = pData->GetPath();
840 pWin->SetTipText( sPath );
844 // set connectors for dependencies here
845 for ( j=0; j<nDirCount; j++ )
847 CommandData *pData = mpPrj->GetObject(j);
848 SByteStringList *pDeps = pData->GetDependencies();
849 if ( pDeps )
851 ByteString sFlagName = pData->GetLogFile();
852 pFlagName = &sFlagName;
853 //pHObject = mpPrjIdMapper->Find( (*pFlagName).GetToken( 0, '.'));//mpSolIdMapper see ReadSource()
854 pHObject = mpPrjIdMapper->Find( sFlagName.GetToken( 0, '.'));
855 if (pHObject)
858 nObjectId = pHObject->GetId();
860 ULONG nDepCount = pDeps->Count();
861 for ( ULONG k=0; k<nDepCount; k++ )
863 pDepName = pDeps->GetObject(k);
864 pHObject = mpPrjIdMapper->Find( (*pDepName).GetToken( 0, '.'));
865 if (pHObject )
867 nHashedId = pHObject->GetId();
868 pStartWin = ObjIdToPtr( mpObjectPrjList, nHashedId );
869 pEndWin = ObjIdToPtr( mpObjectPrjList, nObjectId );
871 AddConnectorToObjects( pStartWin, pEndWin );
873 else
875 String sMessage;
876 sMessage += String::CreateFromAscii("can't find ");
877 sMessage += String( *pDepName, RTL_TEXTENCODING_UTF8 );
878 sMessage += String::CreateFromAscii(".\ndependency ignored");
879 WarningBox aBox( GetDepWin(), WB_OK, sMessage);
880 aBox.Execute();
888 break;
891 ByteString sNullDir = "null";
892 nObjectId = AddPrjObject( sNullDir, FALSE);
893 ObjectWin *pWin = ObjIdToPtr( mpObjectPrjList, nObjectId );
894 pWin->SetViewMask( 0x0001 );
895 mpGraphPrjWin->EnablePaint( TRUE );
896 //debug
897 // int test_l = GetStartPrj(mpPrjIdMapper, mpObjectPrjList);
898 // ObjectWin *pTestWin = ObjIdToPtr( mpObjectPrjList, test_l );
899 AutoArrange( mpPrjIdMapper, mpObjectPrjList, GetStartPrj(mpPrjIdMapper, mpObjectPrjList), 0, GetStartPrj(mpPrjIdMapper, mpObjectPrjList) );
900 mpGraphWin->Hide();
901 mpGraphPrjWin->Show();
902 mpGraphPrjWin->Invalidate();
904 return bReturn;
907 /*****************************************************************************/
908 USHORT SolDep::CloseWindow()
909 /*****************************************************************************/
912 ((SystemWindow*)mpProcessWin)->Close();
913 return 0;
916 /*****************************************************************************/
917 void SolDep::ShowHelp()
918 /*****************************************************************************/
920 SvFileStream aHelpFile( String::CreateFromAscii( "g:\\soldep.hlp" ), STREAM_READ );
921 String aHelpText;
922 ByteString aGetStr;
924 if ( aHelpFile.IsOpen() )
926 while ( aHelpFile.ReadLine( aGetStr ) )
928 aHelpText += String (aGetStr, RTL_TEXTENCODING_UTF8);
929 aHelpText += String::CreateFromAscii("\n");
932 else
933 aHelpText = String::CreateFromAscii("No Helpfile found.");
935 SolHelpDlg aHelpDlg( mpBaseWin, DtSodResId( RID_SD_DIALOG_HELP ));
936 aHelpDlg.maMLEHelp.SetText( aHelpText );
937 aHelpDlg.maMLEHelp.SetReadOnly();
938 aHelpDlg.maMLEHelp.EnableFocusSelectionHide( TRUE );
939 aHelpDlg.Execute();
942 /*****************************************************************************/
943 BOOL SolDep::FindProject()
944 /*****************************************************************************/
946 SolFindProjectDlg aFindProjectDlg( GetDepWin(), GetObjectList() );
947 ObjectWin* pObjectWin = NULL;
948 mpObjectList->ResetSelectedObject();
949 if (IsHideMode())
951 GetDepWin()->Invalidate();
954 mpFocusWin=NULL;
956 if ( aFindProjectDlg.Execute() == RET_OK ) {
957 msProject = aFindProjectDlg.GetProject();
958 //now we have a project string
959 pObjectWin = mpObjectList->GetPtrByName( msProject );
960 mpObjectList->ResetSelectedObject();
961 MarkObjects( pObjectWin );
963 return FALSE;
966 BOOL SolDep::MarkObjects( ObjectWin* pObjectWin )
968 if (pObjectWin)
970 if (!(pObjectWin->IsNullObject()))
972 pObjectWin->SetMarkMode( MARKMODE_SELECTED );
973 pObjectWin->MarkNeeded();
974 pObjectWin->MarkDepending();
975 if (IsHideMode())
977 GetDepWin()->Invalidate();
979 } else
981 fprintf(stdout,"null\n");
984 return TRUE;
987 void SolDep::Resize()
989 //funzt! muß aber von der applikation aufgerufen werden.
990 Point aOutPos = Point( 0, 0 );
991 Size aOutSize = mpProcessWin->GetOutputSizePixel();
992 // calculate output size
993 ULONG nTaskHeight = maToolBox.CalcWindowSizePixel().Height();
994 ULONG nTaskWidth = maToolBox.CalcWindowSizePixel().Width();
995 Size aSize( aOutSize.Width(), nTaskHeight );
997 // ULONG nMenuHeight = 0;
998 Point aGraphWinPos = Point(0,0);
999 Size aGraphWinSize = Size(0,0);
1001 //weiß nicht wie: nMenuHeight = aMenuBar.GetWindow()->GetSizePixel().Height(); //Höhe des Menues
1003 //aInRect = pTBManager->Resize( Rectangle( aOutPos, aOutSize );
1004 // Set Docking-Rectangle for ToolBar
1005 Rectangle aInRect;
1007 if (( !maToolBox.IsFloatingMode() ) && ( maToolBox.GetAlign() == WINDOWALIGN_TOP ))
1009 // waagerechte Toolbar oben
1010 maToolBox.SetPosSizePixel( aOutPos, Size( aOutSize.Width(), maToolBox.CalcWindowSizePixel().Height()));
1011 if( maToolBox.IsVisible())
1013 Point aOutPosTmp;
1014 Size aOutSizeTmp;
1015 aOutPosTmp = Point( aOutPos.X(), aOutPos.Y() + maToolBox.CalcWindowSizePixel().Height());
1016 aOutSizeTmp = Size( aOutSize.Width(), aOutSize.Height() - maToolBox.CalcWindowSizePixel().Height());
1017 aInRect = Rectangle( aOutPosTmp, aOutSizeTmp );
1018 aGraphWinPos = Point( 0, nTaskHeight );
1019 aGraphWinSize = Size( aOutSize.Width(), aOutSize.Height() - nTaskHeight);
1022 if (( !maToolBox.IsFloatingMode() ) && ( maToolBox.GetAlign() == WINDOWALIGN_BOTTOM ))
1024 // waagerechte Toolbar unten
1025 Point aTbPos = Point( aOutPos.X(), aOutPos.Y() + aOutSize.Height() - maToolBox.CalcWindowSizePixel().Height());
1026 Size aTbSize = Size( aOutSize.Width(), maToolBox.CalcWindowSizePixel().Height());
1027 maToolBox.SetPosSizePixel( aTbPos, aTbSize );
1028 if( maToolBox.IsVisible())
1030 Point aOutPosTmp;
1031 Size aOutSizeTmp;
1032 aOutPosTmp = Point( aOutPos.X(), aOutPos.Y() + maToolBox.CalcWindowSizePixel().Height());
1033 aOutSizeTmp = Size( aOutSize.Width(), aOutSize.Height() - maToolBox.CalcWindowSizePixel().Height());
1034 aInRect = Rectangle( aOutPosTmp, aOutSizeTmp );
1035 aGraphWinPos = Point( 0, 0 );
1036 aGraphWinSize = Size( aOutSize.Width(), aOutSize.Height() - nTaskHeight);
1039 if (( !maToolBox.IsFloatingMode() ) && ( maToolBox.GetAlign() == WINDOWALIGN_LEFT ))
1041 // senkrechte ToolBar links
1042 maToolBox.SetPosSizePixel( aOutPos, Size( maToolBox.CalcWindowSizePixel().Width(), aOutSize.Height()));
1043 if( maToolBox.IsVisible())
1045 Point aOutPosTmp;
1046 Size aOutSizeTmp;
1047 aOutPosTmp = Point( aOutPos.X() + maToolBox.CalcWindowSizePixel().Width(), aOutPos.Y());
1048 aOutSizeTmp = Size( aOutSize.Width()- maToolBox.CalcWindowSizePixel().Width(), aOutSize.Height());
1049 aInRect = Rectangle( aOutPosTmp, aOutSizeTmp );
1050 aGraphWinPos = Point( nTaskWidth, 0 );
1051 aGraphWinSize = Size( aOutSize.Width() - nTaskWidth, aOutSize.Height());
1054 if (( !maToolBox.IsFloatingMode() ) && ( maToolBox.GetAlign() == WINDOWALIGN_RIGHT ))
1056 // senkrechte ToolBar rechts
1057 Point aTbPos = Point( aOutPos.X() + aOutSize.Width() - maToolBox.CalcWindowSizePixel().Width(), aOutPos.Y());
1058 Size aTbSize= Size( maToolBox.CalcWindowSizePixel().Width(), aOutSize.Height());
1059 maToolBox.SetPosSizePixel( aTbPos, aTbSize);
1060 if( maToolBox.IsVisible())
1062 Point aOutPosTmp;
1063 Size aOutSizeTmp;
1064 aOutPosTmp = Point( aOutPos.X() + maToolBox.CalcWindowSizePixel().Width(), aOutPos.Y());
1065 aOutSizeTmp = Size( aOutSize.Width()- maToolBox.CalcWindowSizePixel().Width(), aOutSize.Height());
1066 aInRect = Rectangle( aOutPosTmp, aOutSizeTmp );
1067 aGraphWinPos = Point( 0, 0 );
1068 aGraphWinSize = Size( aOutSize.Width() - nTaskWidth, aOutSize.Height());
1072 Rectangle rout = Rectangle( Point( 0,0 ), aOutSize ); //OutputToScreenPixel( aOutPos )
1073 Rectangle rin = Rectangle( Point( 0,0 ),//OutputToScreenPixel( Point( aOutPos.X() - 20, aInRect.Top())
1074 Size( aOutSize.Width(), aOutSize.Height()));
1076 Rectangle rout = mpProcessWin->OutputToScreenPixel( aOutPos );
1077 Rectangle rin = Rectangle( Point( 0,0 ),//OutputToScreenPixel( Point( aOutPos.X() - 20, aInRect.Top())
1078 Size( aOutSize.Width(), aOutSize.Height()));
1080 maToolBox.SetDockingRects( rout, rin );
1082 BOOL bFloating = maToolBox.IsFloatingMode();
1084 if ( bFloating )
1086 GetGraphWin()->SetPosSizePixel(Point(0,0),aOutSize);
1087 //if (IsPrjView() && (mpPrjDep)) mpPrjDep->Resize();
1088 if (maToolBox.IsVisible()) maToolBox.Show();
1089 } else
1091 GetGraphWin()->SetPosSizePixel( aGraphWinPos, aGraphWinSize );
1093 if (maToolBox.IsVisible()) maToolBox.Show();
1096 USHORT SolDep::AddConnectorPrjView( ObjectWin* pStartWin, ObjectWin* pEndWin )
1098 // DBG_ASSERT( FALSE , "not yet" );
1099 ByteString sEndName = pEndWin->GetBodyText();
1100 ByteString sStartName = pStartWin->GetBodyText();
1101 if ( sStartName != ByteString("null"))
1103 CommandData* pEndData = mpPrj->GetDirectoryData( sEndName );
1104 SByteStringList* pDeps = pEndData->GetDependencies();
1105 if ( pDeps )
1106 pDeps->PutString( &sStartName );
1107 else
1109 pDeps = new SByteStringList();
1110 pEndData->SetDependencies( pDeps );
1111 pDeps->PutString( &sStartName );
1112 pEndData->GetDependencies();
1115 return AddConnectorToObjects( pStartWin, pEndWin );
1118 USHORT SolDep::RemoveConnectorPrjView( ObjectWin* pStartWin, ObjectWin* pEndWin )
1120 ByteString sEndName = pEndWin->GetBodyText();
1121 ByteString sStartName = pStartWin->GetBodyText();
1122 CommandData* pEndData = mpPrj->GetDirectoryData( sEndName );
1123 SByteStringList* pDeps = pEndData->GetDependencies();
1124 if ( pDeps )
1126 ByteString* pString;
1127 ULONG nDepsCount = pDeps->Count();
1128 for ( ULONG j = nDepsCount; j > 0; j-- )
1130 pString = pDeps->GetObject( j - 1 );
1131 if ( pString->GetToken( 0, '.') == sStartName )
1132 pDeps->Remove( pString );
1135 return RemoveConnectorFromObjects( pStartWin, pEndWin );
1138 USHORT SolDep::AutoArrange( SolIdMapper* pIdMapper, ObjectList* pObjLst, ULONG nTopId, ULONG nBottmId, ULONG aObjID )
1140 AutoArrangeDlgStart();
1141 OptimizePos(pIdMapper, pObjLst, nTopId, nBottmId, aObjID );
1142 AutoArrangeDlgStop();
1143 return 0;
1146 Point SolDep::CalcPos( USHORT nSet, USHORT nIndex )
1148 int nRowIndex = nIndex / DEPPER_MAX_WIDTH;
1149 ULONG nPosX = mnXOffset + nRowIndex % 3 * GetDefSize().Width() / 3 + ( nIndex - ( DEPPER_MAX_WIDTH * nRowIndex )) * (GetDefSize().Width() + OBJWIN_X_SPACING );
1151 ULONG nPosY = ( nSet + mnLevelOffset + nRowIndex ) * ( GetDefSize().Height() + OBJWIN_Y_SPACING ) + OBJWIN_Y_SPACING;
1152 Point aPos( nPosX, nPosY );
1153 return aPos;
1156 ULONG SolDep::CalcXOffset( ULONG nObjectsToFit )
1158 long nDynXOffs;
1159 long nXMiddle;
1160 ULONG nTrigger;
1162 nXMiddle = GetDepWin()->PixelToLogic( GetDepWin()->GetSizePixel()).Width() / 2;
1163 if ( nObjectsToFit > DEPPER_MAX_WIDTH )
1164 nObjectsToFit = DEPPER_MAX_WIDTH - 1 + DEPPER_MAX_WIDTH % 2;
1165 nTrigger = ( nObjectsToFit - 1 ) / 2;
1166 nDynXOffs = ( GetDefSize().Width() + OBJWIN_X_SPACING ) * nTrigger;
1167 ULONG nXOffs = nXMiddle - nDynXOffs;
1169 if ( ULONG(nXMiddle - nDynXOffs) < mnMinDynXOffs )
1170 mnMinDynXOffs = nXMiddle - nDynXOffs;
1172 return nXOffs;
1176 double SolDep::CalcDistSum( ObjWinList* pObjList, DistType eDistType )
1178 ObjectWin* pWin;
1179 Connector* pCon;
1180 ULONG nObjCount = pObjList->Count();
1181 double dRetVal = 0;
1182 double dWinVal;
1183 USHORT i, j;
1184 BOOL bIsStart;
1186 for ( i = 0; i < nObjCount; i++ )
1188 pWin = pObjList->GetObject( i );
1190 if ( pWin && pWin->IsVisible())
1192 j = 0;
1193 dWinVal = 0;
1194 while ( (pCon = pWin->GetConnector( j )) )
1196 if ( pCon->IsVisible()) {
1197 bIsStart = pCon->IsStart( pWin );
1198 if ( eDistType != BOTH )
1199 if ( eDistType == TOPDOWN )
1201 if ( bIsStart )
1203 pCon->UpdatePosition( pWin, FALSE );
1204 dWinVal += pCon->GetLen() * pWin->mnHeadDist;
1207 else
1209 if ( !bIsStart )
1211 pCon->UpdatePosition( pWin, FALSE );
1212 dWinVal += pCon->GetLen() * pWin->mnRootDist;
1216 else
1218 pCon->UpdatePosition( pWin, FALSE );
1219 if ( !bIsStart )
1220 dWinVal += pCon->GetLen() * ( pWin->mnHeadDist + 1 );
1221 else
1222 dWinVal += pCon->GetLen() * pWin->mnRootDist;
1225 j++;
1227 // if ( j != 0 )
1228 // dWinVal /= j;
1229 dRetVal += dWinVal;
1233 return dRetVal;
1236 USHORT SolDep::Impl_Traveller( ObjectWin* pWin, USHORT nDepth )
1238 USHORT i = 0;
1239 ObjectWin* pNewWin;
1240 Connector* pCon;
1242 nDepth++;
1244 USHORT nMaxDepth = nDepth;
1246 pWin->mbVisited = TRUE;
1247 pWin->mnRootDist = Max ( nDepth, pWin-> mnRootDist );
1248 if ( nDepth > DEPPER_MAX_DEPTH )
1250 DBG_ASSERT( nDepth != DEPPER_MAX_DEPTH + 1, "Ringabhängigkeit!" );
1251 nDepth++;
1252 return DEP_ENDLES_RECURSION_FOUND;
1255 while ( (pCon = pWin->GetConnector( i )) )
1257 if ( pCon->IsStart( pWin )&& pCon->IsVisible() ) //removed: don't show null_project
1259 pNewWin = pCon->GetOtherWin( pWin );
1260 nMaxDepth = Max( Impl_Traveller( pNewWin, nDepth ), nMaxDepth );
1261 if( nMaxDepth == DEP_ENDLES_RECURSION_FOUND )
1263 mpTravellerList->Insert( pWin, LIST_APPEND );
1264 return DEP_ENDLES_RECURSION_FOUND;
1267 i++;
1269 pWin->mnHeadDist = MAX( pWin->mnHeadDist, nMaxDepth - nDepth );
1270 return nMaxDepth;
1274 double SolDep::Impl_PermuteMin( ObjWinList& rObjList, Point* pPosArray, ObjWinList& rResultList, double dMinDist, ULONG nStart, ULONG nSize, DistType eDistType )
1277 ULONG i, j, l;
1278 ULONG nEnd = nStart + nSize;
1279 ObjectWin* pSwapWin;
1280 ULONG nLevelObjCount = rObjList.Count();
1282 //dont use full recusion for more than 6 objects
1283 if ( nLevelObjCount > 6 )
1285 srand(( unsigned ) time( NULL ));
1287 ULONG nIdx1, nIdx2;
1288 for ( i = 0; i < 101; i++ )
1290 UpdateSubProgrssBar(i);
1291 for ( j = 0; j < 100; j++ )
1293 nIdx1 = (ULONG) ( double( rand() ) / RAND_MAX * nLevelObjCount );
1294 while ( rObjList.GetObject( nIdx1 ) == NULL )
1295 nIdx1 = (ULONG) ( double( rand() ) / RAND_MAX * nLevelObjCount );
1296 nIdx2 = (ULONG) ( double( rand() ) / RAND_MAX * nLevelObjCount );
1297 while ( nIdx1 == nIdx2 || nIdx2 == nLevelObjCount )
1298 nIdx2 = (ULONG) ( double( rand() ) / RAND_MAX * nLevelObjCount );
1300 pSwapWin = rObjList.GetObject( nIdx1 );
1301 if ( pSwapWin )
1302 pSwapWin->SetCalcPosPixel( pPosArray[ nIdx2 ] );
1303 pSwapWin = rObjList.Replace( pSwapWin, nIdx2 );
1304 if ( pSwapWin )
1305 pSwapWin->SetCalcPosPixel( pPosArray[ nIdx1 ] );
1306 rObjList.Replace( pSwapWin, nIdx1 );
1308 double dCurDist = CalcDistSum( &rObjList, eDistType );
1310 if ( dCurDist < dMinDist )
1312 dMinDist = dCurDist;
1313 rResultList.Clear();
1314 for ( l = 0; l < nLevelObjCount; l++ )
1316 pSwapWin = rObjList.GetObject( l );
1317 rResultList.Insert( pSwapWin, LIST_APPEND);
1320 // if ( dCurDist > dMinDist * 1.5 )
1321 if ( dCurDist > dMinDist * 15 )
1323 pSwapWin = rObjList.GetObject( nIdx1 );
1324 if ( pSwapWin )
1325 pSwapWin->SetCalcPosPixel( pPosArray[ nIdx2 ] );
1326 pSwapWin = rObjList.Replace( pSwapWin, nIdx2 );
1327 if ( pSwapWin )
1328 pSwapWin->SetCalcPosPixel( pPosArray[ nIdx1 ] );
1329 rObjList.Replace( pSwapWin, nIdx1 );
1334 else
1336 for ( i = nStart ; i < nEnd; i++)
1338 if ( nSize > 1 )
1340 pSwapWin = rObjList.GetObject( i );
1341 pSwapWin = rObjList.Replace( pSwapWin, nStart );
1342 rObjList.Replace( pSwapWin, i );
1343 double dPermuteDist = Impl_PermuteMin( rObjList, pPosArray, rResultList, dMinDist, nStart + 1, nSize - 1, eDistType );
1344 dMinDist = MIN( dMinDist, dPermuteDist);
1345 pSwapWin = rObjList.GetObject( i );
1346 pSwapWin = rObjList.Replace( pSwapWin, nStart );
1347 rObjList.Replace( pSwapWin, i );
1350 else
1352 for ( l = 0; l < nLevelObjCount; l++ )
1354 pSwapWin = rObjList.GetObject( l );
1355 if ( pSwapWin )
1356 pSwapWin->SetCalcPosPixel( pPosArray[ l ] );
1359 double dCurDist = CalcDistSum( &rObjList, eDistType );
1361 if ( dCurDist < dMinDist )
1363 dMinDist = dCurDist;
1364 rResultList.Clear();
1365 for ( l = 0; l < nLevelObjCount; l++ )
1367 pSwapWin = rObjList.GetObject( l );
1368 rResultList.Insert( pSwapWin, LIST_APPEND);
1376 return dMinDist;
1380 USHORT SolDep::OptimizePos(SolIdMapper* pIdMapper, ObjectList* pObjLst, ULONG nTopId, ULONG nBottmId, ULONG aObjID )
1382 ObjWinList aWorkList;
1383 ObjectWin* pWin;
1384 Connector* pCon;
1385 USHORT nRootDist = (USHORT) -1;
1386 USHORT i, j, k, l, nRetVal;
1387 USHORT LevelUse[ DEPPER_MAX_DEPTH ];
1388 USHORT LevelSecUse[ DEPPER_MAX_DEPTH ];
1389 ObjWinList* LevelList[ DEPPER_MAX_DEPTH ];
1390 ObjWinList* LevelSecList[ DEPPER_MAX_DEPTH ];
1391 Point aPosArray[ DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH ];
1393 mnMinDynXOffs = 0xffff;
1395 for ( i = 0; i < DEPPER_MAX_DEPTH; i++ )
1397 LevelUse[ i ] = 0;
1398 LevelList[ i ] = NULL;
1399 LevelSecUse[ i ] = 0;
1400 LevelSecList[ i ] = NULL;
1403 GetDepWin()->EnablePaint( FALSE );
1405 ULONG nObjCount = pObjLst->Count();
1406 for ( i = 0; i < nObjCount; i++ )
1408 pWin = pObjLst->GetObject( i );
1409 if ( pWin->IsVisible()) {
1410 pWin->mbVisited = FALSE;
1411 pWin->mnHeadDist = 0;
1412 pWin->mnRootDist = 0;
1414 // find initial objects which need to be connected with
1415 // root object
1416 j = 0;
1417 USHORT nStartCount = 0;
1418 USHORT nEndCount = 0;
1419 while ( (pCon = pWin->GetConnector( j )) )
1421 if ( pCon->IsVisible()) { //null_project
1422 if( pCon->IsStart( pWin ))
1423 nStartCount++;
1424 else
1426 nEndCount = 1;
1427 break;
1430 j++;
1433 if ( nStartCount > 0 && nEndCount == 0 )
1434 if ( nTopId != pWin->GetId())
1435 AddConnectorToObjects( pObjLst, nTopId, pWin->GetId());
1440 pWin = ObjIdToPtr( pObjLst, nTopId );
1442 if ( mpTravellerList )
1444 mpTravellerList->Clear();
1445 delete mpTravellerList;
1447 mpTravellerList = new ObjWinList();
1448 // set root and top distance
1449 nRetVal = Impl_Traveller( pWin, nRootDist );
1451 DBG_ASSERT( nRetVal < DEPPER_MAX_DEPTH , "zu tief" );
1452 if ( nRetVal == DEP_ENDLES_RECURSION_FOUND )
1454 WriteToErrorFile();
1455 return nRetVal;
1458 ULONG nUnvisited = 0;
1459 ULONG nUnvisYOffs = 0;
1461 // seperate mainstream, secondary and unconnected
1462 for ( i = 0; i < nObjCount; i++ )
1464 pWin = pObjLst->GetObject( i );
1465 if ( pWin->IsVisible()) {
1466 if (( pWin->mnHeadDist + pWin->mnRootDist ) == nRetVal )
1468 if ( !LevelList[ pWin->mnHeadDist ] )
1469 LevelList[ pWin->mnHeadDist ] = new ObjWinList;
1470 LevelList[ pWin->mnHeadDist ]->Insert( pWin );
1471 LevelUse[ pWin->mnHeadDist ]++;
1473 else
1474 if ( pWin->mbVisited )
1476 if ( !LevelSecList[ nRetVal - pWin->mnRootDist ] )
1477 LevelSecList[ nRetVal - pWin->mnRootDist ] = new ObjWinList;
1478 LevelSecList[ nRetVal - pWin->mnRootDist ]->Insert( pWin );
1479 LevelSecUse[ nRetVal - pWin->mnRootDist ]++;
1481 else
1483 // need to be arranged more intelligent...
1484 Point aPos( 5, nUnvisYOffs );
1485 pWin->SetCalcPosPixel( aPos );
1487 Point aTmpPos = pWin->GetCalcPosPixel();
1488 pWin->SetPosPixel( mpBaseWin->LogicToPixel( aTmpPos ));
1490 nUnvisYOffs += pWin->PixelToLogic( pWin->GetSizePixel()).Height();
1491 nUnvisited++;
1496 mnLevelOffset = 0;
1498 USHORT nScaleVal;
1500 if ( nRetVal == 0 )
1501 nScaleVal = 1;
1502 else
1503 nScaleVal = nRetVal;
1505 i = 0;
1507 USHORT nStep = 0;
1509 while ( LevelList[ i ] )
1511 UpdateMainProgressBar(i, nScaleVal, nStep);
1512 DBG_ASSERT( LevelUse[ i ] == LevelList[ i ]->Count() , "level index im a..." );
1513 ObjectWin* pSwapWin;
1514 ULONG nLevelObjCount = LevelList[ i ]->Count();
1516 if ( nLevelObjCount % 2 == 0 )
1518 LevelList[ i ]->Insert( NULL, LIST_APPEND );
1519 nLevelObjCount++;
1520 // LevelUse bleibt orginal...
1521 // LevelUse[ i ]++;
1524 // catch too big lists
1525 DBG_ASSERT( nLevelObjCount < DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH , "graph zu breit! dat geiht nich gut. breaking" );
1526 if ( nLevelObjCount >= DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH )
1528 WarningBox aWBox( mpBaseWin, WB_OK, String::CreateFromAscii("graph zu breit! dat geiht nich gut. breaking"));
1529 aWBox.Execute();
1530 break;
1532 mnXOffset = CalcXOffset( nLevelObjCount );
1533 aWorkList.Clear();
1535 // initial positioning for mainstream
1536 for ( j = 0; j < nLevelObjCount; j++ )
1538 pSwapWin = LevelList[ i ]->GetObject( j );
1539 aWorkList.Insert( pSwapWin, LIST_APPEND);
1540 Point aPos = CalcPos( i, j );
1541 aPosArray[ j ] = aPos;
1542 if ( pSwapWin )
1543 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1546 double dMinDist = CalcDistSum( LevelList[ i ] );
1548 // optimize mainstream order and return best matching list in "aWorkList"
1549 dMinDist = MIN( dMinDist, Impl_PermuteMin( *(LevelList[ i ]), aPosArray, aWorkList, dMinDist, 0, nLevelObjCount ));
1551 // set optimized positions - may still be wrong from later tries
1552 for ( j = 0; j < nLevelObjCount; j++ )
1554 pSwapWin = aWorkList.GetObject( j );
1555 if ( pSwapWin )
1556 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1559 if ( LevelSecList[ i ] != NULL )
1561 ULONG nLevelSecObjCount = LevelSecList[ i ]->Count();
1562 // expand list for better positioning
1563 while ( nLevelSecObjCount + LevelUse[ i ] < DEPPER_MAX_WIDTH - 1 )
1565 LevelSecList[ i ]->Insert( NULL, LIST_APPEND );
1566 nLevelSecObjCount++;
1568 if ( ( nLevelSecObjCount + LevelUse[ i ])% 2 == 0 )
1570 LevelSecList[ i ]->Insert( NULL, LIST_APPEND );
1571 nLevelSecObjCount++;
1574 DBG_ASSERT( nLevelSecObjCount < DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH , "graph zu breit! dat geiht nich gut. breaking" );
1575 if ( nLevelObjCount >= DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH )
1577 WarningBox aWBox( mpBaseWin, WB_OK, String::CreateFromAscii("graph zu breit! dat geiht nich gut. breaking"));
1578 aWBox.Execute();
1579 break;
1581 mnXOffset = CalcXOffset( LevelUse[ i ] + nLevelSecObjCount );
1582 aWorkList.Clear();
1584 l = 0;
1585 BOOL bUsedPos;
1587 // find free positions for secondary objects
1588 for ( j = 0; j < ( LevelUse[ i ] + nLevelSecObjCount ) ; j++ )
1590 Point aPos = CalcPos( i, j );
1591 bUsedPos = FALSE;
1592 // is already occupied?
1593 for ( k = 0; k < nLevelObjCount; k++ )
1595 if ( LevelList[ i ]->GetObject( k ) )
1596 if ( aPos == LevelList[ i ]->GetObject( k )->GetCalcPosPixel() )
1597 bUsedPos = TRUE;
1599 // if its free, add to pool
1600 if ( !bUsedPos )
1602 aPosArray[ l ] = aPos;
1603 l++;
1607 // initial positioning for secodaries
1608 for ( j = 0 ; j < nLevelSecObjCount ; j++ )
1610 pSwapWin = LevelSecList[ i ]->GetObject( j );
1611 aWorkList.Insert( pSwapWin, LIST_APPEND);
1612 if ( pSwapWin )
1613 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1615 dMinDist = CalcDistSum( LevelSecList[ i ] );
1617 dMinDist = MIN( dMinDist, Impl_PermuteMin( *(LevelSecList[ i ]), aPosArray, aWorkList, dMinDist, 0, nLevelSecObjCount ));
1619 // set optimized positions - may still be wrong from later tries
1620 for ( j = 0; j < nLevelSecObjCount; j++ )
1622 pSwapWin = aWorkList.GetObject( j );
1623 if ( pSwapWin )
1624 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1626 if ( LevelUse[ i ] + LevelSecUse[ i ] > DEPPER_MAX_WIDTH )
1627 mnLevelOffset++;
1629 if ( LevelUse[ i ] + LevelSecUse[ i ] > DEPPER_MAX_WIDTH )
1630 mnLevelOffset+= ( LevelUse[ i ] + LevelSecUse[ i ] ) / DEPPER_MAX_WIDTH ;
1631 i++;
1634 mnMinDynXOffs = 0xffff;
1636 // and back again...
1637 // get better results form already preoptimized upper and lower rows
1641 i--;
1642 UpdateMainProgressBar(i, nScaleVal, nStep, TRUE); // TRUE ~ counting down
1643 if ( LevelUse[ i ] + LevelSecUse[ i ] > DEPPER_MAX_WIDTH )
1644 mnLevelOffset-= ( LevelUse[ i ] + LevelSecUse[ i ] ) / DEPPER_MAX_WIDTH ;
1645 ObjectWin* pSwapWin;
1646 ULONG nLevelObjCount = LevelList[ i ]->Count();
1647 mnXOffset = CalcXOffset( nLevelObjCount );
1648 aWorkList.Clear();
1650 for ( j = 0; j < nLevelObjCount; j++ )
1652 pSwapWin = LevelList[ i ]->GetObject( j );
1653 aWorkList.Insert( pSwapWin, LIST_APPEND);
1654 Point aPos = CalcPos( i, j );
1655 aPosArray[ j ] = aPos;
1656 //no need to do this stuff....... ?????
1657 if ( pSwapWin )
1658 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1661 double dMinDist = CalcDistSum( LevelList[ i ], BOTH );
1663 dMinDist = MIN( dMinDist, Impl_PermuteMin( *(LevelList[ i ]), aPosArray, aWorkList, dMinDist, 0, nLevelObjCount, BOTH ));
1664 // wrong position for remaping - keep old positions for comparing
1665 for ( j = 0; j < nLevelObjCount; j++ )
1667 pSwapWin = aWorkList.GetObject( j );
1668 if ( pSwapWin )
1669 // pSwapWin->SetCalcPosPixel( mpBaseWin->LogicToPixel( aPosArray[ j ] ));
1670 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1673 if ( LevelSecList[ i ] != NULL )
1675 ULONG nLevelSecObjCount = LevelSecList[ i ]->Count();
1676 mnXOffset = CalcXOffset( LevelUse[ i ] + nLevelSecObjCount );
1677 aWorkList.Clear();
1679 l = 0;
1680 BOOL bUsedPos;
1682 for ( j = 0; j < ( LevelUse[ i ] + nLevelSecObjCount ) ; j++ )
1684 Point aPos = CalcPos( i, j );
1685 bUsedPos = FALSE;
1686 // could be faster
1687 for ( k = 0; k < nLevelObjCount; k++ )
1689 if ( LevelList[ i ]->GetObject( k ) )
1690 if ( aPos == LevelList[ i ]->GetObject( k )->GetCalcPosPixel() )
1691 bUsedPos = TRUE;
1693 if ( !bUsedPos )
1695 aPosArray[ l ] = aPos;
1696 l++;
1700 for ( j = 0 ; j < nLevelSecObjCount ; j++ )
1702 pSwapWin = LevelSecList[ i ]->GetObject( j );
1703 aWorkList.Insert( pSwapWin, LIST_APPEND);
1704 if ( pSwapWin )
1705 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1707 dMinDist = CalcDistSum( LevelSecList[ i ], BOTH );
1709 dMinDist = MIN( dMinDist, Impl_PermuteMin( *(LevelSecList[ i ]), aPosArray, aWorkList, dMinDist, 0, nLevelSecObjCount, BOTH ));
1710 // wrong position for remaping - keep old positions for comparing
1711 for ( j = 0; j < nLevelSecObjCount; j++ )
1713 pSwapWin = aWorkList.GetObject( j );
1714 if ( pSwapWin )
1715 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1718 // i--;
1719 } while ( i != 0 );
1720 SetMainProgressBar( 100 );
1722 ULONG nNewXSize = ( DEPPER_MAX_WIDTH + 1 ) * ( OBJWIN_X_SPACING + GetDefSize().Width() );
1724 // ULONG aObjID = GetStart(pIdMapper, pObjLst) //hier muß man switchen GetStart/GetPrjStart oder so
1726 ObjectWin* pObjWin = ObjIdToPtr( pObjLst, aObjID);
1728 ULONG nNewYSize = pObjWin->GetCalcPosPixel().Y() + GetDefSize().Height() + 2 * OBJWIN_Y_SPACING;
1729 if (( nUnvisYOffs + GetDefSize().Height()) > nNewYSize )
1730 nNewYSize = nUnvisYOffs + GetDefSize().Height();
1732 MapMode aMapMode = GetDepWin()->GetMapMode();
1733 Size aTmpSize( (ULONG) (double(nNewXSize) * double( aMapMode.GetScaleX())), (ULONG) (double( nNewYSize) * double( aMapMode.GetScaleY())));
1735 Size aNowSize( GetGraphWin()->GetSizePixel());
1737 if ( GetDepWin()->LogicToPixel( aNowSize ).Width() > aTmpSize.Width() )
1738 aTmpSize.Width() = GetDepWin()->LogicToPixel( aNowSize ).Width() ;
1740 if ( GetDepWin()->LogicToPixel( aNowSize ).Height() > aTmpSize.Height() )
1741 aTmpSize.Height() = GetDepWin()->LogicToPixel( aNowSize ).Height() ;
1743 // if ( nZoomed <= 0 )
1744 // {
1745 // mpBaseWin->SetSizePixel( aTmpSize );
1746 // mpGraphWin->SetTotalSize( aTmpSize );
1747 // mpGraphWin->EndScroll( 0, 0 );
1748 // }
1750 // now remap all objects
1751 ULONG nAllObjCount = pObjLst->Count();
1752 Point aTmpPos;
1753 for ( j = 0; j < nAllObjCount; j++ )
1755 pWin = pObjLst->GetObject( j );
1756 if ( pWin->IsVisible()) {
1757 aTmpPos = pWin->GetCalcPosPixel();
1758 if ( pWin->mbVisited )
1760 // reserve space for unconnected
1761 aTmpPos.X() -= mnMinDynXOffs;
1762 aTmpPos.X() += GetDefSize().Width() + OBJWIN_X_SPACING;
1763 // center window
1764 aTmpPos.X() += GetDefSize().Width() / 2;
1765 aTmpPos.X() -= pWin->PixelToLogic( pWin->GetSizePixel()).Width() / 2 ;
1767 pWin->SetPosPixel( GetDepWin()->LogicToPixel( aTmpPos ));
1770 aWorkList.Clear();
1771 GetDepWin()->EnablePaint( TRUE );
1772 GetDepWin()->Invalidate();
1773 //LevelListen loeschen Hä? Welche Levellisten?
1775 //Update all Connectors
1776 // --> To be done: Don't call twice Object1-Connector-Object2
1777 ObjectWin* pObject1;
1778 for ( i = 0 ; i < nObjCount ; i++)
1780 pObject1 = pObjLst->GetObject( i );
1781 if ( pObject1->IsVisible())
1782 pObject1->UpdateConnectors();
1784 return 0;
1787 void SolDep::WriteToErrorFile()
1789 //Needs some improvement
1790 ObjectWin* pWin;
1791 WarningBox aWBox( mpBaseWin, WB_OK, String::CreateFromAscii("graph too deep! dat geiht nich gut.\nlook at depper.err in your Tmp-directory\nfor list of objects"));
1792 aWBox.Execute();
1793 char *tmpdir = getenv("TMP");
1794 char *errfilebasename = "depper.err";
1795 char *ErrFileName = (char*) malloc( strlen( tmpdir ) + strlen( errfilebasename) + 3 );
1796 *ErrFileName = '\0';
1797 strcat( ErrFileName, tmpdir );
1798 strcat( ErrFileName, "\\" );
1799 strcat( ErrFileName, errfilebasename );
1800 FILE* pErrFile = fopen( "depper.err", "w+" );
1801 if ( pErrFile )
1803 for ( USHORT i = 0; i < mpTravellerList->Count(); i++ )
1805 pWin = mpTravellerList->GetObject( i );
1806 fprintf( pErrFile, " %s -> \n", (pWin->GetBodyText()).GetBuffer());
1808 fclose( pErrFile );