OOO330
[LibreOffice.git] / soldep / source / soldep.cxx
blobce94afbbab927a6393f94bf26569c36ad319327c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 //TBD: ToolBox handling prjview/back
29 #include <osl/file.hxx>
30 #include <rtl/ustring.hxx>
31 #include <tools/debug.hxx>
32 #include <bootstrp/sstring.hxx>
33 #include <svtools/filedlg.hxx>
34 #include <tools/iparser.hxx>
35 #include <tools/geninfo.hxx>
36 #include <vcl/gdimtf.hxx>
37 #include <vcl/bitmap.hxx>
38 #include <appdef.hxx>
39 #include "time.h"
40 #include <soldep/depper.hxx>
41 #include <soldep/soldep.hxx>
42 #include <soldep/soldlg.hxx>
43 #include "dtsodcmp.hrc"
45 IMPLEMENT_HASHTABLE_OWNER( SolIdMapper, ByteString, ULONG* );
46 //IMPLEMENT_HASHTABLE_OWNER( PrjIdMapper, ByteString, ULONG* );
47 #define EVENT_RESIZE 0x00000001
48 #define MIN(a,b) (a)<(b)?(a):(b)
49 #define MAX(a,b) (a)>(b)?(a):(b)
52 //ByteString sDelimiterLine("#==========================================================================");
56 // class SolDep
59 /*****************************************************************************/
60 SolDep::SolDep( Window* pBaseWindow )
61 /*****************************************************************************/
62 : Depper( pBaseWindow ),
63 mbBServer(FALSE),
64 mpTravellerList( NULL ),
65 mbIsHide( FALSE )
67 mnSolWinCount = 0;
68 mnSolLastId = 0;
69 // mpPrjIdMapper = new SolIdMapper( 63997 );
70 maTaskBarFrame.EnableAlwaysOnTop();
71 maTaskBarFrame.Show();
72 maToolBox.SetPosSizePixel( Point( 0,0 ), Size( 1100,35 ));
73 maToolBox.SetSelectHdl( LINK ( this, SolDep, ToolSelect ));
74 maToolBox.Show();
76 mpBaseWin->AddChildEventListener( LINK( this, SolDep, ChildWindowEventListener ));
78 // Kontext-Menue (gehört zu soldep.cxx)
79 InitContextMenueMainWnd();
80 InitContextMenuePrjViewWnd( mpBasePrjWin );
83 /*****************************************************************************/
84 SolDep::~SolDep()
85 /*****************************************************************************/
87 mpBaseWin->RemoveChildEventListener( LINK( this, SolDep, ChildWindowEventListener ) );
88 delete mpSolIdMapper;
89 delete mpStarWriter;
90 delete mpStandLst;
93 /*****************************************************************************/
94 void SolDep::Init()
95 /*****************************************************************************/
97 InformationParser aParser;
98 String sStandLst( GetDefStandList(), RTL_TEXTENCODING_ASCII_US );
99 mpStandLst = aParser.Execute( sStandLst );
100 ByteString aUpdater( getenv("UPDATER") );
101 if ( mpStandLst && (aUpdater == "YES") ) {
102 if ( GetVersion() )
103 ReadSource( TRUE );
104 } else
106 ReadSource(); // if stand.lst isn't available
110 /*****************************************************************************/
111 void SolDep::Init( ByteString &rVersion, GenericInformationList *pVersionList )
112 /*****************************************************************************/
114 // Interface for bs
115 mbBServer=TRUE;
116 if ( pVersionList )
117 mpStandLst = new GenericInformationList( *pVersionList );
118 else {
119 InformationParser aParser;
120 String sStandLst( GetDefStandList(), RTL_TEXTENCODING_ASCII_US );
121 mpStandLst = aParser.Execute( sStandLst );
123 if ( mpStandLst ) {
124 msVersionMajor = ByteString( rVersion );
125 ReadSource(TRUE); //call from build server set UPDATER to TRUE
129 /*****************************************************************************/
130 IMPL_LINK( SolDep, ChildWindowEventListener, VclSimpleEvent*, pEvent )
131 /*****************************************************************************/
133 if ( pEvent && pEvent->ISA( VclWindowEvent ) )
135 ProcessChildWindowEvent( *static_cast< VclWindowEvent* >( pEvent ) );
137 return 0;
141 /*****************************************************************************/
142 void SolDep::ProcessChildWindowEvent( const VclWindowEvent& _rVclWindowEvent )
143 /*****************************************************************************/
145 Window* pChildWin = _rVclWindowEvent.GetWindow();
146 // Window* pParentWin = pChildWin->GetParent();
147 //Resize();
148 if ( isAlive() )
150 ULONG id = _rVclWindowEvent.GetId();
151 switch ( id )
153 case VCLEVENT_USER_MOUSEBUTTON_DOWN:
155 ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
156 if( pObjWin )
158 // handle mouse click on ObjectWin object
159 ObjectWin* pWin = (ObjectWin*) pChildWin;
160 //GetObjectList()->ResetSelectedObject();
161 if (IsHideMode()) // simple mouse click left
163 pWin->CaptureMouse();
164 pWin->SetMarkMode( MARKMODE_SELECTED );
165 pWin->MarkNeeded();
166 pWin->MarkDepending();
167 pWin->Invalidate();
168 } else
170 pWin->LoseFocus();
171 pWin->SetMarkMode( MARKMODE_SELECTED );
172 pWin->UnsetMarkMode( MARKMODE_ACTIVATED );
173 pWin->MarkNeeded( TRUE );
174 pWin->MarkDepending( TRUE );
179 break;
180 case VCLEVENT_USER_MOUSEBUTTON_DOWN_ALT:
182 ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
183 if( pObjWin )
185 ObjectWin* pWin = (ObjectWin*) pChildWin;
186 MarkObjects( pWin );
189 break;
190 case VCLEVENT_USER_MOUSEBUTTON_DOWN_DBLCLICK:
192 ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
193 if( pObjWin )
195 if (IsHideMode()) ToggleHideDependency();
196 ByteString text = ((ObjectWin*) pChildWin)->GetBodyText();
197 ViewContent(text);
200 break;
201 case VCLEVENT_USER_MOUSEBUTTON_UP_SHFT:
203 ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
204 if( pObjWin )
206 ObjectWin* pWin = (ObjectWin*) pChildWin;
207 GetDepWin()->NewConnector( pWin );
210 break;
211 case VCLEVENT_USER_MOUSEBUTTON_UP:
213 ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
214 if( pObjWin )
216 ObjectWin* pWin = (ObjectWin*) pChildWin;
217 pWin->ReleaseMouse();
218 pWin->SetMarkMode(MARKMODE_SELECTED);
219 GetDepWin()->Invalidate();
222 break;
223 } // switch
224 } // if isAlive
225 //fprintf(stdout,"BLA::Resize: %d\n",pChildWin);
228 /*****************************************************************************/
229 IMPL_LINK( SolDep, ToolSelect, SoldepToolBox* , pBox)
230 /*****************************************************************************/
232 USHORT nItemId = pBox->GetCurItemId();
233 switch ( nItemId )
235 case TID_SOLDEP_FIND:
236 FindProject();
237 break;
238 case TID_SOLDEP_CREATEMETA :
240 VirtualDevice aVDev;
241 aVDev.SetMapMode( MAP_100TH_MM );
242 GDIMetaFile aMtf;
243 aVDev.EnableOutput( FALSE );
244 aMtf.Record( &aVDev );
246 aVDev.SetLineColor( Color( COL_BLACK ) );
247 aVDev.SetTextAlign( ALIGN_TOP );
249 Size aSize( GetDepWin()->GetOutputSizePixel() );
250 long nXMin = aSize.Width();
251 long nXMax = 0;
252 long nYMax = 0;
253 long nYMin = aSize.Height();
255 for ( USHORT i=0; i<mpObjectList->Count(); i++ )
257 Point aPoint = mpObjectList->GetObject(i)->GetPosPixel();
258 Size aSize = mpObjectList->GetObject(i)->GetSizePixel();
259 nXMin = MIN( aPoint.X(), nXMin );
260 nXMax = MAX( aPoint.X() + aSize.Width(), nXMax );
261 nYMin = MIN( aPoint.Y(), nYMin );
262 nYMax = MAX( aPoint.Y() + aSize.Height(), nYMax );
265 Point aOffset( nXMin, nYMin );
266 aOffset = aVDev.PixelToLogic( aOffset );
268 GetDepWin()->DrawOutput( &aVDev, aOffset );
269 for ( USHORT i=0; i<mpObjectList->Count(); i++ )
270 if ( mpObjectList->GetObject(i)->IsVisible() )
271 mpObjectList->GetObject(i)->DrawOutput( &aVDev, aOffset );
273 aMtf.Stop();
274 aMtf.WindStart();
275 aMtf.SetPrefMapMode( aVDev.GetMapMode() );
276 Size aDevSize( nXMax-nXMin + 10, nYMax-nYMin + 10);
277 aDevSize = aVDev.PixelToLogic( aDevSize );
278 aMtf.SetPrefSize( aDevSize );
279 SvFileStream aStream( String::CreateFromAscii("d:\\out.svm"), STREAM_STD_READWRITE );
280 aMtf.Write( aStream );
281 break;
283 case TID_SOLDEP_HIDE_INDEPENDEND:
285 ToggleHideDependency();
286 for ( USHORT i=0; i<mpObjectList->Count(); i++ )
287 mpObjectList->GetObject(i)->SetViewMask(!mbIsHide);
289 maToolBox.CheckItem(TID_SOLDEP_HIDE_INDEPENDEND, IsHideMode());
290 GetDepWin()->Invalidate(); //repaint Main-View
292 break;
293 case TID_SOLDEP_SELECT_WORKSPACE:
294 if (mpStandLst)
296 if (GetVersion()) // Version dialog box
298 delete mpSolIdMapper;
299 delete mpStarWriter;
300 mpObjectList->ClearAndDelete();
301 ReadSource(TRUE);
304 break;
305 case TID_SOLDEP_BACK:
306 maToolBox.HideItem(TID_SOLDEP_BACK);
307 maToolBox.ShowItem(TID_SOLDEP_SELECT_WORKSPACE); //disabled for prj view (doubleclick ObjWin)
308 maToolBox.ShowItem(TID_SOLDEP_HIDE_INDEPENDEND); //disabled for prj view (doubleclick ObjWin)
309 maToolBox.ShowItem(TID_SOLDEP_FIND); //disabled for prj view (doubleclick ObjWin)
310 maToolBox.Resize();
311 TogglePrjViewStatus();
312 break;
314 return 0;
317 /*****************************************************************************/
318 void SolDep::ToggleHideDependency()
319 /*****************************************************************************/
321 mbIsHide = !mbIsHide;
322 maToolBox.CheckItem(TID_SOLDEP_HIDE_INDEPENDEND, IsHideMode());
323 ObjectWin* pWin = GetObjectList()->GetObject( 0 );
324 pWin->ToggleHideMode();
327 /*****************************************************************************/
328 BOOL SolDep::GetVersion()
329 /*****************************************************************************/
331 SolSelectVersionDlg aVersionDlg( GetDepWin(), mpStandLst );
332 if ( aVersionDlg.Execute() == RET_OK ) {
333 msVersionMajor = aVersionDlg.GetVersionMajor();
334 msVersionMinor = aVersionDlg.GetVersionMinor();
335 return TRUE;
337 return FALSE;
340 void SolDep::InitContextMenueMainWnd()
342 InitContextMenuePrjViewWnd( mpBaseWin );
343 return; // Disable not actually supported items
345 mpBaseWin->mpPopup->InsertItem( DEPPOPUP_AUTOARRANGE, String::CreateFromAscii("Autoarrange")) ;
346 mpBaseWin->mpPopup->InsertSeparator();
347 mpBaseWin->mpPopup->InsertItem( DEPPOPUP_READ_SOURCE, String::CreateFromAscii("Revert all changes") );
348 mpBaseWin->mpPopup->InsertSeparator();
349 mpBaseWin->mpPopup->InsertItem( DEPPOPUP_OPEN_SOURCE, String::CreateFromAscii("Open") );
350 mpBaseWin->mpPopup->InsertItem( DEPPOPUP_WRITE_SOURCE, String::CreateFromAscii("Save") );
353 void SolDep::InitContextMenuePrjViewWnd(DepWin* pBaseWin )
355 // temp. disabled pBaseWin->mpPopup->InsertItem( DEPPOPUP_NEW, String::CreateFromAscii("New object") );
356 pBaseWin->mpPopup->InsertItem( DEPPOPUP_ZOOMIN, String::CreateFromAscii("Zoom in") );
357 pBaseWin->mpPopup->InsertItem( DEPPOPUP_ZOOMOUT, String::CreateFromAscii("Zoom out") );
358 pBaseWin->mpPopup->InsertSeparator();
359 // temp disabled pBaseWin->mpPopup->InsertItem( DEPPOPUP_CLEAR, String::CreateFromAscii("Clear") );
360 pBaseWin->mpPopup->InsertItem( DEPPOPUP_SHOW_TOOLBOX, String::CreateFromAscii("Show Toolbox") );
363 /*****************************************************************************/
364 ObjectWin *SolDep::RemoveObject( USHORT nId, BOOL bDelete )
365 /*****************************************************************************/
367 Prj* pPrj;
369 //hshtable auf stand halten
370 ObjectWin* pWin = RemoveObjectFromList( mpObjectList, mnSolWinCount, nId, FALSE );
371 if ( pWin )
373 ByteString aBodyText( pWin->GetBodyText() );
374 if( (pPrj = mpStarWriter->GetPrj( aBodyText )) )
376 mpStarWriter->Remove( pPrj );
377 //cleanup ist teuer...
378 mpStarWriter->CleanUp();
379 delete pPrj;
381 else
382 DBG_ASSERT( FALSE, "project not found - write" );
384 mpSolIdMapper->Delete( aBodyText );
385 if ( bDelete )
386 delete pWin;
387 return pWin;
389 else
390 return NULL;
393 /*****************************************************************************/
394 ULONG SolDep::AddObject( ByteString& rBodyText, BOOL bInteract )
395 /*****************************************************************************/
397 ULONG nObjectId;
398 if ( bInteract )
400 nObjectId = HandleNewPrjDialog( rBodyText );
402 else
404 //hashtable auf stand halten
405 MyHashObject* pHObject;
406 nObjectId = AddObjectToList( mpBaseWin, mpObjectList, mnSolLastId, mnSolWinCount, rBodyText, FALSE );
407 pHObject = new MyHashObject( nObjectId, ObjIdToPtr(mpObjectList, nObjectId ));
408 mpSolIdMapper->Insert( rBodyText, pHObject );
410 return nObjectId;
413 /*****************************************************************************/
414 ULONG SolDep::AddPrjObject( ByteString& rBodyText, BOOL bInteract )
415 /*****************************************************************************/
417 ULONG nObjectId;
418 if ( bInteract )
420 nObjectId = HandleNewDirectoryDialog( rBodyText );
422 else
424 //hshtable auf stand halten
425 MyHashObject* pHObject;
426 nObjectId = AddObjectToList( mpBasePrjWin, mpObjectPrjList, mnPrjLastId, mnPrjWinCount, rBodyText );
427 pHObject = new MyHashObject( nObjectId, ObjIdToPtr( mpObjectPrjList, nObjectId ));
428 mpPrjIdMapper->Insert( rBodyText, pHObject ); // mpPrjIdMapper
430 return nObjectId;
433 /*****************************************************************************/
434 USHORT SolDep::AddConnector( ObjectWin* pStartWin, ObjectWin* pEndWin )
435 /*****************************************************************************/
437 // DBG_ASSERT( FALSE , "not yet" );
438 ByteString sEndName = pEndWin->GetBodyText();
439 ByteString sStartName = pStartWin->GetBodyText();
441 Prj* pPrj = mpStarWriter->GetPrj( sEndName );
442 if ( pPrj )
444 pPrj->AddDependencies( sStartName );
445 return AddConnectorToObjects( pStartWin, pEndWin );
447 else
449 DBG_ASSERT( FALSE , "non existing Project" );
450 return 1;
454 /*****************************************************************************/
455 USHORT SolDep::RemoveConnector( ObjectWin* pStartWin, ObjectWin* pEndWin )
456 /*****************************************************************************/
458 SByteStringList* pPrjDeps = NULL;
459 ByteString sEndName = pEndWin->GetBodyText();
460 ByteString sStartName = pStartWin->GetBodyText();
462 Prj* pPrj = mpStarWriter->GetPrj( sEndName );
463 pPrjDeps = pPrj->GetDependencies( FALSE );
464 if ( pPrjDeps )
466 ByteString* pString;
467 ULONG nPrjDepsCount = pPrjDeps->Count();
468 for ( ULONG j = nPrjDepsCount; j > 0; j-- )
470 pString = pPrjDeps->GetObject( j - 1 );
471 if ( pString->GetToken( 0, '.') == sStartName )
472 pPrjDeps->Remove( pString );
476 return RemoveConnectorFromObjects( pStartWin, pEndWin );
479 /*****************************************************************************/
480 void SolDep::RemoveAllObjects( ObjectList* pObjLst )
481 /*****************************************************************************/
484 Depper::RemoveAllObjects( pObjLst );
486 if ( mpSolIdMapper )
488 delete mpSolIdMapper;
489 mpSolIdMapper = NULL;
491 if ( mpStarWriter )
493 delete mpStarWriter;
494 mpStarWriter = NULL;
498 /*****************************************************************************/
499 ULONG SolDep::GetStart(SolIdMapper* pIdMapper, ObjectList* pObjList)
500 /*****************************************************************************/
502 // DBG_ASSERT( FALSE , "soldep" );
503 MyHashObject* pHObject = pIdMapper->Find( "null" );//null_project
505 if ( !pHObject ) {
506 ByteString sNullPrj = "null";//null_project
507 ULONG nObjectId = AddObject( sNullPrj, FALSE );
508 ObjIdToPtr( pObjList, nObjectId )->SetViewMask( 1 );
509 return nObjectId;
512 return pHObject->GetId();
515 /*****************************************************************************/
516 ULONG SolDep::GetStartPrj(SolIdMapper* , ObjectList* )
517 /*****************************************************************************/
519 // DBG_ASSERT( FALSE , "prjdep" );
520 MyHashObject* pHObject = mpPrjIdMapper->Find( ByteString( "null" ) ); //null_dir
521 if ( !pHObject )
523 ByteString bsNull("null");
524 ULONG nObjectId = AddPrjObject( bsNull, FALSE); //null_dir
525 return nObjectId;
527 else
528 return pHObject->GetId();
531 /*****************************************************************************/
532 USHORT SolDep::OpenSource()
533 /*****************************************************************************/
535 if ( mpStandLst ) {
536 if ( GetVersion())
537 return ReadSource();
539 return 0;
542 /*****************************************************************************/
543 USHORT SolDep::ReadSource(BOOL bUpdater)
544 /*****************************************************************************/
546 mpBaseWin->EnablePaint( FALSE );
547 mpBaseWin->Hide();
548 ULONG nObjectId, nHashedId;
549 ULONG i;
550 MyHashObject* pHObject;
551 ByteString* pStr;
552 ObjectWin *pStartWin, *pEndWin;
554 mpSolIdMapper = new SolIdMapper( 63997 );
555 if (mpStandLst && bUpdater)
557 mpStarWriter = new StarWriter( mpStandLst, msVersionMajor, msVersionMinor, TRUE );
558 } else
560 SolarFileList* pSolarFileList;
561 pSolarFileList = GetPrjListFromDir();
562 mpStarWriter = new StarWriter( pSolarFileList, TRUE );
564 ByteString sTitle( SOLDEPL_NAME );
565 if ( mpStarWriter->GetMode() == STAR_MODE_SINGLE_PARSE ) {
566 sTitle += ByteString( " - mode: single file [" );
567 sTitle += (ByteString) mpStarWriter->GetName();
568 sTitle += ByteString( "]" );
570 else if ( mpStarWriter->GetMode() == STAR_MODE_MULTIPLE_PARSE ) {
571 sTitle += ByteString( " - mode: multiple files [" );
572 sTitle += ByteString( "]" );
574 SetTitle( String( sTitle, RTL_TEXTENCODING_UTF8) );
576 ULONG nCount = mpStarWriter->Count();
577 for ( i=0; i<nCount; i++ )
579 Prj *pPrj = mpStarWriter->GetObject(i);
580 ByteString sPrjName = pPrj->GetProjectName();
581 nObjectId = AddObject( sPrjName, FALSE );
582 ObjIdToPtr( mpObjectList, nObjectId )->SetViewMask( 1 );
584 for ( i=0; i<nCount; i++ )
586 Prj *pPrj = mpStarWriter->GetObject(i);
587 SByteStringList *pLst = pPrj->GetDependencies( FALSE );
588 if ( pLst )
590 ULONG nDepCount = pLst->Count();
591 for ( ULONG m=0; m<nDepCount; m++)
593 pStr = pLst->GetObject(m);
594 pHObject = mpSolIdMapper->Find( *pStr );
595 /*if ( !pHObject )
597 // create new prj
598 Prj *pNewPrj = new Prj( *pStr );
599 ByteString sPrjName = pNewPrj->GetProjectName();
600 nObjectId = AddObject( sPrjName, FALSE );
601 pHObject = mpSolIdMapper->Find( *pStr );
602 ObjIdToPtr( mpObjectList, nObjectId )->SetViewMask( 2 );
605 if ( pHObject )
607 nHashedId = pHObject->GetId();
608 ByteString sF_Os2 = pPrj->GetProjectName();
609 pStr = &sF_Os2;
610 pHObject = mpSolIdMapper->Find( *pStr );
611 nObjectId = pHObject->GetId();
612 pStartWin = ObjIdToPtr( mpObjectList, nHashedId );
613 pEndWin = ObjIdToPtr( mpObjectList, nObjectId );
614 AddConnectorToObjects( pStartWin, pEndWin );
619 if (!IsPrjView())
621 AutoArrange( mpSolIdMapper, mpObjectList, GetStart(mpSolIdMapper,mpObjectList), 0, GetStart(mpSolIdMapper,mpObjectList) );
622 GetDepWin()->EnablePaint( TRUE );
624 return 0;
627 SolarFileList* SolDep::GetPrjListFromDir()
629 SolarFileList* pSolarFileList = new SolarFileList();
630 String sPrjDir( String::CreateFromAscii( "prj" ));
631 String sBuildLst( String::CreateFromAscii( "build.lst" ));
632 DirEntry aCurrent( getenv( SOURCEROOT ) );
634 aCurrent.ToAbs();
635 Dir aDir( aCurrent, FSYS_KIND_DIR );
637 USHORT nEntries = aDir.Count();
638 if( nEntries )
640 UniStringList aSortDirList;
641 for ( USHORT n = 0; n < nEntries; n++ )
643 DirEntry& rEntry = aDir[n];
644 UniString aName( rEntry.GetName() );
645 if( aName.Len() && ( aName.GetChar(0) != '.' ) && rEntry.Exists() )
647 rEntry += DirEntry( sPrjDir );
648 rEntry += DirEntry( sBuildLst );
649 if (rEntry.Exists())
651 pSolarFileList->Insert( new String( rEntry.GetFull() ), LIST_APPEND );
652 ByteString aName_dbg(rEntry.GetFull(),RTL_TEXTENCODING_UTF8);
653 fprintf(stdout, "bla:%s\n", aName_dbg.GetBuffer());
658 if ( !pSolarFileList->Count() )
660 //is empty!! TBD
661 delete pSolarFileList;
662 return NULL;
664 return pSolarFileList;
667 /*****************************************************************************/
668 USHORT SolDep::WriteSource()
669 /*****************************************************************************/
671 /* zur Sicherheit deaktiviert
672 USHORT nMode = mpStarWriter->GetMode();
673 if ( nMode == STAR_MODE_SINGLE_PARSE ) {
674 ByteString sFileName = mpStarWriter->GetName();
675 if ( sFileName.Len()) {
676 mpStarWriter->Write( String( sFileName, RTL_TEXTENCODING_UTF8) );
677 mpStarWriter->RemoveProject( ByteString( "null")); //null_project
680 else if ( nMode == STAR_MODE_MULTIPLE_PARSE ) {
681 // *OBO*
682 //String sRoot = mpStarWriter->GetSourceRoot();
683 //nicht mehr unterstützt mpStarWriter->GetSourceRoot()
684 ByteString sFileName = mpStarWriter->GetName();
685 DirEntry aEntry( sFileName );
686 aEntry.ToAbs();
687 aEntry = aEntry.GetPath().GetPath().GetPath();
688 String sRoot = aEntry.GetFull();
690 if ( sRoot.Len()) {
691 mpStarWriter->RemoveProject( ByteString( "null")); //null_project
692 mpStarWriter->WriteMultiple( sRoot );
696 return 1;
699 USHORT SolDep::Load( const ByteString& rFileName )
701 // moved from depper class
702 DBG_ASSERT( FALSE , "you are dead!" );
703 SvFileStream aInFile( String( rFileName, RTL_TEXTENCODING_UTF8 ), STREAM_READ );
704 depper_head dh;
705 ULONG i;
706 ULONG nLoadOffs = mnSolLastId; //or Prj??
707 ObjectWin* pNewWin;
708 aInFile.Read( &dh, sizeof( dh ));
710 ULONG nObjCount = dh.nObjectCount;
711 ULONG nCnctrCount = dh.nCnctrCount;
713 for ( i=0; i < nObjCount ; i++ )
715 ObjectWin* pWin = new ObjectWin( mpBaseWin, WB_BORDER );
716 pWin->Load( aInFile );
717 pNewWin = ObjIdToPtr( mpObjectList, AddObjectToList( mpBaseWin, mpObjectList, mnSolLastId, mnSolWinCount, pWin->GetBodyText(), FALSE ));
718 pNewWin->SetId( nLoadOffs + pWin->GetId());
719 pNewWin->SetPosPixel( pWin->GetPosPixel());
720 pNewWin->SetSizePixel( pWin->GetSizePixel());
723 ULONG nStartId;
724 ULONG nEndId;
725 // ueber addconnector fuehren!
726 for ( i=0; i < nCnctrCount ; i++ )
728 Connector* pCon = new Connector( mpBaseWin, WB_NOBORDER );
729 pCon->Load( aInFile );
731 nStartId = nLoadOffs + pCon->GetStartId();
732 nEndId = nLoadOffs + pCon->GetEndId();
734 ObjectWin* pStartWin = ObjIdToPtr( mpObjectList, nStartId );
735 ObjectWin* pEndWin = ObjIdToPtr( mpObjectList, nEndId );
737 pCon->Initialize( pStartWin, pEndWin );
741 return 0;
744 /*****************************************************************************/
745 BOOL SolDep::ViewContent( ByteString& rObjectName )
746 /*****************************************************************************/
748 mpFocusWin = NULL;
749 SetPrjViewStatus(TRUE);
751 for ( ULONG i = 0; i < mpObjectList->Count() && !mpFocusWin; i++ )
752 if ( mpObjectList->GetObject( i )->HasFocus())
753 mpFocusWin = mpObjectList->GetObject( i );
754 //HideObjectsAndConnections( mpObjectList );
755 mpProcessWin->Resize();
756 GetDepWin()->Show();
757 return InitPrj( rObjectName );
760 /*****************************************************************************/
761 BOOL SolDep::InitPrj( ByteString& rListName )
762 /*****************************************************************************/
764 ULONG nObjectId, nHashedId;
765 ULONG i, j;
766 MyHashObject* pHObject;
767 ByteString *pDepName;
768 ByteString *pFlagName;
769 Prj* pPrj;
770 ObjectWin *pStartWin, *pEndWin;
771 maToolBox.HideItem(TID_SOLDEP_SELECT_WORKSPACE);
772 maToolBox.HideItem(TID_SOLDEP_HIDE_INDEPENDEND);
773 maToolBox.HideItem(TID_SOLDEP_FIND);
774 maToolBox.ShowItem(TID_SOLDEP_BACK);
775 maToolBox.Invalidate();
777 //clean up
778 mpObjectPrjList->ClearAndDelete();
779 GetDepWin()->ClearConnectorList();
780 if (mpPrjIdMapper) delete mpPrjIdMapper;
781 mpPrjIdMapper = new SolIdMapper( 63997 ); //generate clean mapper
782 mnPrjWinCount = 0;
783 mnPrjLastId = 0;
785 ULONG nCount = mpStarWriter->Count();
786 GetDepWin()->EnablePaint( FALSE );
787 Point aPnt = GetGraphWin()->GetPosPixel();
788 Size aSize = GetGraphWin()->GetSizePixel();
790 GetGraphWin()->SetPosSizePixel( aPnt, aSize ); // Hier wird das Window gesetzt
792 BOOL bReturn = FALSE;
794 for ( i=0; i<nCount; i++ )
796 // pPrj->GetProjectName() returns the name of
797 // the project e.g. svtools
798 pPrj = mpStarWriter->GetObject(i);
799 ByteString sPrjName = pPrj->GetProjectName();
800 if ( sPrjName == rListName )
802 bReturn = TRUE;
804 mpPrj = mpStarWriter->GetObject(i);
805 ULONG nDirCount = mpPrj->Count();
806 for ( j=0; j<nDirCount; j++ )
808 CommandData *pData = mpPrj->GetObject(j);
809 fprintf( stdout, "\tProjectDir : %s\n",
810 pData->GetLogFile().GetBuffer());
811 // pData->GetLogFile() contains internal project IDs
812 // e.g. st_mkout etc.
813 if ( pData->GetLogFile() != "" )
815 ByteString sItem = pData->GetLogFile();
816 nObjectId = AddPrjObject( sItem, FALSE);
817 // there may be faster ways......
818 ObjectWin *pWin = ObjIdToPtr( mpObjectPrjList, nObjectId );
819 pWin->SetViewMask( 0x0001 );
820 // pData->GetPath() contains internal project directories
821 // e.g. svtools/inc etc.
822 ByteString sPath = pData->GetPath();
823 pWin->SetTipText( sPath );
827 // set connectors for dependencies here
828 for ( j=0; j<nDirCount; j++ )
830 CommandData *pData = mpPrj->GetObject(j);
831 SByteStringList *pDeps = pData->GetDependencies();
832 if ( pDeps )
834 ByteString sFlagName = pData->GetLogFile();
835 pFlagName = &sFlagName;
836 //pHObject = mpPrjIdMapper->Find( (*pFlagName).GetToken( 0, '.'));//mpSolIdMapper see ReadSource()
837 pHObject = mpPrjIdMapper->Find( sFlagName.GetToken( 0, '.'));
838 if (pHObject)
841 nObjectId = pHObject->GetId();
843 ULONG nDepCount = pDeps->Count();
844 for ( ULONG k=0; k<nDepCount; k++ )
846 pDepName = pDeps->GetObject(k);
847 pHObject = mpPrjIdMapper->Find( (*pDepName).GetToken( 0, '.'));
848 if (pHObject )
850 nHashedId = pHObject->GetId();
851 pStartWin = ObjIdToPtr( mpObjectPrjList, nHashedId );
852 pEndWin = ObjIdToPtr( mpObjectPrjList, nObjectId );
854 AddConnectorToObjects( pStartWin, pEndWin );
856 else
858 String sMessage;
859 sMessage += String::CreateFromAscii("can't find ");
860 sMessage += String( *pDepName, RTL_TEXTENCODING_UTF8 );
861 sMessage += String::CreateFromAscii(".\ndependency ignored");
862 WarningBox aBox( GetDepWin(), WB_OK, sMessage);
863 aBox.Execute();
871 break;
874 ByteString sNullDir = "null";
875 nObjectId = AddPrjObject( sNullDir, FALSE);
876 ObjectWin *pWin = ObjIdToPtr( mpObjectPrjList, nObjectId );
877 pWin->SetViewMask( 0x0001 );
878 mpGraphPrjWin->EnablePaint( TRUE );
879 //debug
880 // int test_l = GetStartPrj(mpPrjIdMapper, mpObjectPrjList);
881 // ObjectWin *pTestWin = ObjIdToPtr( mpObjectPrjList, test_l );
882 AutoArrange( mpPrjIdMapper, mpObjectPrjList, GetStartPrj(mpPrjIdMapper, mpObjectPrjList), 0, GetStartPrj(mpPrjIdMapper, mpObjectPrjList) );
883 mpGraphWin->Hide();
884 mpGraphPrjWin->Show();
885 mpGraphPrjWin->Invalidate();
887 return bReturn;
890 /*****************************************************************************/
891 USHORT SolDep::CloseWindow()
892 /*****************************************************************************/
895 ((SystemWindow*)mpProcessWin)->Close();
896 return 0;
899 /*****************************************************************************/
900 void SolDep::ShowHelp()
901 /*****************************************************************************/
903 SvFileStream aHelpFile( String::CreateFromAscii( "g:\\soldep.hlp" ), STREAM_READ );
904 String aHelpText;
905 ByteString aGetStr;
907 if ( aHelpFile.IsOpen() )
909 while ( aHelpFile.ReadLine( aGetStr ) )
911 aHelpText += String (aGetStr, RTL_TEXTENCODING_UTF8);
912 aHelpText += String::CreateFromAscii("\n");
915 else
916 aHelpText = String::CreateFromAscii("No Helpfile found.");
918 SolHelpDlg aHelpDlg( mpBaseWin, DtSodResId( RID_SD_DIALOG_HELP ));
919 aHelpDlg.maMLEHelp.SetText( aHelpText );
920 aHelpDlg.maMLEHelp.SetReadOnly();
921 aHelpDlg.maMLEHelp.EnableFocusSelectionHide( TRUE );
922 aHelpDlg.Execute();
925 /*****************************************************************************/
926 BOOL SolDep::FindProject()
927 /*****************************************************************************/
929 SolFindProjectDlg aFindProjectDlg( GetDepWin(), GetObjectList() );
930 ObjectWin* pObjectWin = NULL;
931 mpObjectList->ResetSelectedObject();
932 if (IsHideMode())
934 GetDepWin()->Invalidate();
937 mpFocusWin=NULL;
939 if ( aFindProjectDlg.Execute() == RET_OK ) {
940 msProject = aFindProjectDlg.GetProject();
941 //now we have a project string
943 pObjectWin = mpObjectList->GetPtrByName( msProject );
944 if (pObjectWin)
946 mpObjectList->ResetSelectedObject();
947 MarkObjects( pObjectWin );
949 else
951 mpObjectList->ResetSelectedObject();
952 for ( USHORT i=0; i<mpObjectList->Count(); i++ )
954 ObjectWin* pObjectWin = mpObjectList->GetObject( i );
955 if ( !pObjectWin->IsTop() )
956 pObjectWin->SetViewMask(FALSE);
960 return FALSE;
963 BOOL SolDep::MarkObjects( ObjectWin* pObjectWin )
965 if (pObjectWin)
967 if (!(pObjectWin->IsNullObject()))
969 pObjectWin->SetMarkMode( MARKMODE_SELECTED );
970 pObjectWin->MarkNeeded();
971 pObjectWin->MarkDepending();
972 if (IsHideMode())
974 GetDepWin()->Invalidate();
976 } else
978 fprintf(stdout,"null\n");
981 return TRUE;
984 void SolDep::Resize()
986 //funzt! muß aber von der applikation aufgerufen werden.
987 Point aOutPos = Point( 0, 0 );
988 Size aOutSize = mpProcessWin->GetOutputSizePixel();
989 // calculate output size
990 ULONG nTaskHeight = maToolBox.CalcWindowSizePixel().Height();
991 ULONG nTaskWidth = maToolBox.CalcWindowSizePixel().Width();
992 Size aSize( aOutSize.Width(), nTaskHeight );
994 // ULONG nMenuHeight = 0;
995 Point aGraphWinPos = Point(0,0);
996 Size aGraphWinSize = Size(0,0);
998 //weiß nicht wie: nMenuHeight = aMenuBar.GetWindow()->GetSizePixel().Height(); //Höhe des Menues
1000 //aInRect = pTBManager->Resize( Rectangle( aOutPos, aOutSize );
1001 // Set Docking-Rectangle for ToolBar
1002 Rectangle aInRect;
1004 if (( !maToolBox.IsFloatingMode() ) && ( maToolBox.GetAlign() == WINDOWALIGN_TOP ))
1006 // waagerechte Toolbar oben
1007 maToolBox.SetPosSizePixel( aOutPos, Size( aOutSize.Width(), maToolBox.CalcWindowSizePixel().Height()));
1008 if( maToolBox.IsVisible())
1010 Point aOutPosTmp;
1011 Size aOutSizeTmp;
1012 aOutPosTmp = Point( aOutPos.X(), aOutPos.Y() + maToolBox.CalcWindowSizePixel().Height());
1013 aOutSizeTmp = Size( aOutSize.Width(), aOutSize.Height() - maToolBox.CalcWindowSizePixel().Height());
1014 aInRect = Rectangle( aOutPosTmp, aOutSizeTmp );
1015 aGraphWinPos = Point( 0, nTaskHeight );
1016 aGraphWinSize = Size( aOutSize.Width(), aOutSize.Height() - nTaskHeight);
1019 if (( !maToolBox.IsFloatingMode() ) && ( maToolBox.GetAlign() == WINDOWALIGN_BOTTOM ))
1021 // waagerechte Toolbar unten
1022 Point aTbPos = Point( aOutPos.X(), aOutPos.Y() + aOutSize.Height() - maToolBox.CalcWindowSizePixel().Height());
1023 Size aTbSize = Size( aOutSize.Width(), maToolBox.CalcWindowSizePixel().Height());
1024 maToolBox.SetPosSizePixel( aTbPos, aTbSize );
1025 if( maToolBox.IsVisible())
1027 Point aOutPosTmp;
1028 Size aOutSizeTmp;
1029 aOutPosTmp = Point( aOutPos.X(), aOutPos.Y() + maToolBox.CalcWindowSizePixel().Height());
1030 aOutSizeTmp = Size( aOutSize.Width(), aOutSize.Height() - maToolBox.CalcWindowSizePixel().Height());
1031 aInRect = Rectangle( aOutPosTmp, aOutSizeTmp );
1032 aGraphWinPos = Point( 0, 0 );
1033 aGraphWinSize = Size( aOutSize.Width(), aOutSize.Height() - nTaskHeight);
1036 if (( !maToolBox.IsFloatingMode() ) && ( maToolBox.GetAlign() == WINDOWALIGN_LEFT ))
1038 // senkrechte ToolBar links
1039 maToolBox.SetPosSizePixel( aOutPos, Size( maToolBox.CalcWindowSizePixel().Width(), aOutSize.Height()));
1040 if( maToolBox.IsVisible())
1042 Point aOutPosTmp;
1043 Size aOutSizeTmp;
1044 aOutPosTmp = Point( aOutPos.X() + maToolBox.CalcWindowSizePixel().Width(), aOutPos.Y());
1045 aOutSizeTmp = Size( aOutSize.Width()- maToolBox.CalcWindowSizePixel().Width(), aOutSize.Height());
1046 aInRect = Rectangle( aOutPosTmp, aOutSizeTmp );
1047 aGraphWinPos = Point( nTaskWidth, 0 );
1048 aGraphWinSize = Size( aOutSize.Width() - nTaskWidth, aOutSize.Height());
1051 if (( !maToolBox.IsFloatingMode() ) && ( maToolBox.GetAlign() == WINDOWALIGN_RIGHT ))
1053 // senkrechte ToolBar rechts
1054 Point aTbPos = Point( aOutPos.X() + aOutSize.Width() - maToolBox.CalcWindowSizePixel().Width(), aOutPos.Y());
1055 Size aTbSize= Size( maToolBox.CalcWindowSizePixel().Width(), aOutSize.Height());
1056 maToolBox.SetPosSizePixel( aTbPos, aTbSize);
1057 if( maToolBox.IsVisible())
1059 Point aOutPosTmp;
1060 Size aOutSizeTmp;
1061 aOutPosTmp = Point( aOutPos.X() + maToolBox.CalcWindowSizePixel().Width(), aOutPos.Y());
1062 aOutSizeTmp = Size( aOutSize.Width()- maToolBox.CalcWindowSizePixel().Width(), aOutSize.Height());
1063 aInRect = Rectangle( aOutPosTmp, aOutSizeTmp );
1064 aGraphWinPos = Point( 0, 0 );
1065 aGraphWinSize = Size( aOutSize.Width() - nTaskWidth, aOutSize.Height());
1069 Rectangle rout = Rectangle( Point( 0,0 ), aOutSize ); //OutputToScreenPixel( aOutPos )
1070 Rectangle rin = Rectangle( Point( 0,0 ),//OutputToScreenPixel( Point( aOutPos.X() - 20, aInRect.Top())
1071 Size( aOutSize.Width(), aOutSize.Height()));
1073 Rectangle rout = mpProcessWin->OutputToScreenPixel( aOutPos );
1074 Rectangle rin = Rectangle( Point( 0,0 ),//OutputToScreenPixel( Point( aOutPos.X() - 20, aInRect.Top())
1075 Size( aOutSize.Width(), aOutSize.Height()));
1077 maToolBox.SetDockingRects( rout, rin );
1079 BOOL bFloating = maToolBox.IsFloatingMode();
1081 if ( bFloating )
1083 GetGraphWin()->SetPosSizePixel(Point(0,0),aOutSize);
1084 //if (IsPrjView() && (mpPrjDep)) mpPrjDep->Resize();
1085 if (maToolBox.IsVisible()) maToolBox.Show();
1086 } else
1088 GetGraphWin()->SetPosSizePixel( aGraphWinPos, aGraphWinSize );
1090 if (maToolBox.IsVisible()) maToolBox.Show();
1093 USHORT SolDep::AddConnectorPrjView( ObjectWin* pStartWin, ObjectWin* pEndWin )
1095 // DBG_ASSERT( FALSE , "not yet" );
1096 ByteString sEndName = pEndWin->GetBodyText();
1097 ByteString sStartName = pStartWin->GetBodyText();
1098 if ( sStartName != ByteString("null"))
1100 CommandData* pEndData = mpPrj->GetDirectoryData( sEndName );
1101 SByteStringList* pDeps = pEndData->GetDependencies();
1102 if ( pDeps )
1103 pDeps->PutString( &sStartName );
1104 else
1106 pDeps = new SByteStringList();
1107 pEndData->SetDependencies( pDeps );
1108 pDeps->PutString( &sStartName );
1109 pEndData->GetDependencies();
1112 return AddConnectorToObjects( pStartWin, pEndWin );
1115 USHORT SolDep::RemoveConnectorPrjView( ObjectWin* pStartWin, ObjectWin* pEndWin )
1117 ByteString sEndName = pEndWin->GetBodyText();
1118 ByteString sStartName = pStartWin->GetBodyText();
1119 CommandData* pEndData = mpPrj->GetDirectoryData( sEndName );
1120 SByteStringList* pDeps = pEndData->GetDependencies();
1121 if ( pDeps )
1123 ByteString* pString;
1124 ULONG nDepsCount = pDeps->Count();
1125 for ( ULONG j = nDepsCount; j > 0; j-- )
1127 pString = pDeps->GetObject( j - 1 );
1128 if ( pString->GetToken( 0, '.') == sStartName )
1129 pDeps->Remove( pString );
1132 return RemoveConnectorFromObjects( pStartWin, pEndWin );
1135 USHORT SolDep::AutoArrange( SolIdMapper* pIdMapper, ObjectList* pObjLst, ULONG nTopId, ULONG nBottmId, ULONG aObjID )
1137 AutoArrangeDlgStart();
1138 OptimizePos(pIdMapper, pObjLst, nTopId, nBottmId, aObjID );
1139 AutoArrangeDlgStop();
1140 return 0;
1143 Point SolDep::CalcPos( USHORT nSet, USHORT nIndex )
1145 int nRowIndex = nIndex / DEPPER_MAX_WIDTH;
1146 ULONG nPosX = mnXOffset + nRowIndex % 3 * GetDefSize().Width() / 3 + ( nIndex - ( DEPPER_MAX_WIDTH * nRowIndex )) * (GetDefSize().Width() + OBJWIN_X_SPACING );
1148 ULONG nPosY = ( nSet + mnLevelOffset + nRowIndex ) * ( GetDefSize().Height() + OBJWIN_Y_SPACING ) + OBJWIN_Y_SPACING;
1149 Point aPos( nPosX, nPosY );
1150 return aPos;
1153 ULONG SolDep::CalcXOffset( ULONG nObjectsToFit )
1155 long nDynXOffs;
1156 long nXMiddle;
1157 ULONG nTrigger;
1159 nXMiddle = GetDepWin()->PixelToLogic( GetDepWin()->GetSizePixel()).Width() / 2;
1160 if ( nObjectsToFit > DEPPER_MAX_WIDTH )
1161 nObjectsToFit = DEPPER_MAX_WIDTH - 1 + DEPPER_MAX_WIDTH % 2;
1162 nTrigger = ( nObjectsToFit - 1 ) / 2;
1163 nDynXOffs = ( GetDefSize().Width() + OBJWIN_X_SPACING ) * nTrigger;
1164 ULONG nXOffs = nXMiddle - nDynXOffs;
1166 if ( ULONG(nXMiddle - nDynXOffs) < mnMinDynXOffs )
1167 mnMinDynXOffs = nXMiddle - nDynXOffs;
1169 return nXOffs;
1173 double SolDep::CalcDistSum( ObjWinList* pObjList, DistType eDistType )
1175 ObjectWin* pWin;
1176 Connector* pCon;
1177 ULONG nObjCount = pObjList->Count();
1178 double dRetVal = 0;
1179 double dWinVal;
1180 USHORT i, j;
1181 BOOL bIsStart;
1183 for ( i = 0; i < nObjCount; i++ )
1185 pWin = pObjList->GetObject( i );
1187 if ( pWin && pWin->IsVisible())
1189 j = 0;
1190 dWinVal = 0;
1191 while ( (pCon = pWin->GetConnector( j )) )
1193 if ( pCon->IsVisible()) {
1194 bIsStart = pCon->IsStart( pWin );
1195 if ( eDistType != BOTH )
1196 if ( eDistType == TOPDOWN )
1198 if ( bIsStart )
1200 pCon->UpdatePosition( pWin, FALSE );
1201 dWinVal += pCon->GetLen() * pWin->mnHeadDist;
1204 else
1206 if ( !bIsStart )
1208 pCon->UpdatePosition( pWin, FALSE );
1209 dWinVal += pCon->GetLen() * pWin->mnRootDist;
1213 else
1215 pCon->UpdatePosition( pWin, FALSE );
1216 if ( !bIsStart )
1217 dWinVal += pCon->GetLen() * ( pWin->mnHeadDist + 1 );
1218 else
1219 dWinVal += pCon->GetLen() * pWin->mnRootDist;
1222 j++;
1224 // if ( j != 0 )
1225 // dWinVal /= j;
1226 dRetVal += dWinVal;
1230 return dRetVal;
1233 USHORT SolDep::Impl_Traveller( ObjectWin* pWin, USHORT nDepth )
1235 USHORT i = 0;
1236 ObjectWin* pNewWin;
1237 Connector* pCon;
1239 nDepth++;
1241 USHORT nMaxDepth = nDepth;
1243 pWin->mbVisited = TRUE;
1244 pWin->mnRootDist = Max ( nDepth, pWin-> mnRootDist );
1245 if ( nDepth > DEPPER_MAX_DEPTH )
1247 DBG_ASSERT( nDepth != DEPPER_MAX_DEPTH + 1, "Ringabhängigkeit!" );
1248 nDepth++;
1249 return DEP_ENDLES_RECURSION_FOUND;
1252 while ( (pCon = pWin->GetConnector( i )) )
1254 if ( pCon->IsStart( pWin )&& pCon->IsVisible() ) //removed: don't show null_project
1256 pNewWin = pCon->GetOtherWin( pWin );
1257 nMaxDepth = Max( Impl_Traveller( pNewWin, nDepth ), nMaxDepth );
1258 if( nMaxDepth == DEP_ENDLES_RECURSION_FOUND )
1260 mpTravellerList->Insert( pWin, LIST_APPEND );
1261 return DEP_ENDLES_RECURSION_FOUND;
1264 i++;
1266 pWin->mnHeadDist = MAX( pWin->mnHeadDist, nMaxDepth - nDepth );
1267 return nMaxDepth;
1271 double SolDep::Impl_PermuteMin( ObjWinList& rObjList, Point* pPosArray, ObjWinList& rResultList, double dMinDist, ULONG nStart, ULONG nSize, DistType eDistType )
1274 ULONG i, j, l;
1275 ULONG nEnd = nStart + nSize;
1276 ObjectWin* pSwapWin;
1277 ULONG nLevelObjCount = rObjList.Count();
1279 //dont use full recusion for more than 6 objects
1280 if ( nLevelObjCount > 6 )
1282 srand(( unsigned ) time( NULL ));
1284 ULONG nIdx1, nIdx2;
1285 for ( i = 0; i < 101; i++ )
1287 UpdateSubProgrssBar(i);
1288 for ( j = 0; j < 100; j++ )
1290 nIdx1 = (ULONG) ( double( rand() ) / RAND_MAX * nLevelObjCount );
1291 while ( rObjList.GetObject( nIdx1 ) == NULL )
1292 nIdx1 = (ULONG) ( double( rand() ) / RAND_MAX * nLevelObjCount );
1293 nIdx2 = (ULONG) ( double( rand() ) / RAND_MAX * nLevelObjCount );
1294 while ( nIdx1 == nIdx2 || nIdx2 == nLevelObjCount )
1295 nIdx2 = (ULONG) ( double( rand() ) / RAND_MAX * nLevelObjCount );
1297 pSwapWin = rObjList.GetObject( nIdx1 );
1298 if ( pSwapWin )
1299 pSwapWin->SetCalcPosPixel( pPosArray[ nIdx2 ] );
1300 pSwapWin = rObjList.Replace( pSwapWin, nIdx2 );
1301 if ( pSwapWin )
1302 pSwapWin->SetCalcPosPixel( pPosArray[ nIdx1 ] );
1303 rObjList.Replace( pSwapWin, nIdx1 );
1305 double dCurDist = CalcDistSum( &rObjList, eDistType );
1307 if ( dCurDist < dMinDist )
1309 dMinDist = dCurDist;
1310 rResultList.Clear();
1311 for ( l = 0; l < nLevelObjCount; l++ )
1313 pSwapWin = rObjList.GetObject( l );
1314 rResultList.Insert( pSwapWin, LIST_APPEND);
1317 // if ( dCurDist > dMinDist * 1.5 )
1318 if ( dCurDist > dMinDist * 15 )
1320 pSwapWin = rObjList.GetObject( nIdx1 );
1321 if ( pSwapWin )
1322 pSwapWin->SetCalcPosPixel( pPosArray[ nIdx2 ] );
1323 pSwapWin = rObjList.Replace( pSwapWin, nIdx2 );
1324 if ( pSwapWin )
1325 pSwapWin->SetCalcPosPixel( pPosArray[ nIdx1 ] );
1326 rObjList.Replace( pSwapWin, nIdx1 );
1331 else
1333 for ( i = nStart ; i < nEnd; i++)
1335 if ( nSize > 1 )
1337 pSwapWin = rObjList.GetObject( i );
1338 pSwapWin = rObjList.Replace( pSwapWin, nStart );
1339 rObjList.Replace( pSwapWin, i );
1340 double dPermuteDist = Impl_PermuteMin( rObjList, pPosArray, rResultList, dMinDist, nStart + 1, nSize - 1, eDistType );
1341 dMinDist = MIN( dMinDist, dPermuteDist);
1342 pSwapWin = rObjList.GetObject( i );
1343 pSwapWin = rObjList.Replace( pSwapWin, nStart );
1344 rObjList.Replace( pSwapWin, i );
1347 else
1349 for ( l = 0; l < nLevelObjCount; l++ )
1351 pSwapWin = rObjList.GetObject( l );
1352 if ( pSwapWin )
1353 pSwapWin->SetCalcPosPixel( pPosArray[ l ] );
1356 double dCurDist = CalcDistSum( &rObjList, eDistType );
1358 if ( dCurDist < dMinDist )
1360 dMinDist = dCurDist;
1361 rResultList.Clear();
1362 for ( l = 0; l < nLevelObjCount; l++ )
1364 pSwapWin = rObjList.GetObject( l );
1365 rResultList.Insert( pSwapWin, LIST_APPEND);
1373 return dMinDist;
1377 USHORT SolDep::OptimizePos(SolIdMapper* pIdMapper, ObjectList* pObjLst, ULONG nTopId, ULONG nBottmId, ULONG aObjID )
1379 ObjWinList aWorkList;
1380 ObjectWin* pWin;
1381 Connector* pCon;
1382 USHORT nRootDist = (USHORT) -1;
1383 USHORT i, j, k, l, nRetVal;
1384 USHORT LevelUse[ DEPPER_MAX_DEPTH ];
1385 USHORT LevelSecUse[ DEPPER_MAX_DEPTH ];
1386 ObjWinList* LevelList[ DEPPER_MAX_DEPTH ];
1387 ObjWinList* LevelSecList[ DEPPER_MAX_DEPTH ];
1388 Point aPosArray[ DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH ];
1390 mnMinDynXOffs = 0xffff;
1392 for ( i = 0; i < DEPPER_MAX_DEPTH; i++ )
1394 LevelUse[ i ] = 0;
1395 LevelList[ i ] = NULL;
1396 LevelSecUse[ i ] = 0;
1397 LevelSecList[ i ] = NULL;
1400 GetDepWin()->EnablePaint( FALSE );
1402 ULONG nObjCount = pObjLst->Count();
1403 for ( i = 0; i < nObjCount; i++ )
1405 pWin = pObjLst->GetObject( i );
1406 if ( pWin->IsVisible()) {
1407 pWin->mbVisited = FALSE;
1408 pWin->mnHeadDist = 0;
1409 pWin->mnRootDist = 0;
1411 // find initial objects which need to be connected with
1412 // root object
1413 j = 0;
1414 USHORT nStartCount = 0;
1415 USHORT nEndCount = 0;
1416 while ( (pCon = pWin->GetConnector( j )) )
1418 if ( pCon->IsVisible()) { //null_project
1419 if( pCon->IsStart( pWin ))
1420 nStartCount++;
1421 else
1423 nEndCount = 1;
1424 break;
1427 j++;
1430 if ( nStartCount > 0 && nEndCount == 0 )
1431 if ( nTopId != pWin->GetId())
1432 AddConnectorToObjects( pObjLst, nTopId, pWin->GetId());
1437 pWin = ObjIdToPtr( pObjLst, nTopId );
1439 if ( mpTravellerList )
1441 mpTravellerList->Clear();
1442 delete mpTravellerList;
1444 mpTravellerList = new ObjWinList();
1445 // set root and top distance
1446 nRetVal = Impl_Traveller( pWin, nRootDist );
1448 DBG_ASSERT( nRetVal < DEPPER_MAX_DEPTH , "zu tief" );
1449 if ( nRetVal == DEP_ENDLES_RECURSION_FOUND )
1451 WriteToErrorFile();
1452 return nRetVal;
1455 ULONG nUnvisited = 0;
1456 ULONG nUnvisYOffs = 0;
1458 // seperate mainstream, secondary and unconnected
1459 for ( i = 0; i < nObjCount; i++ )
1461 pWin = pObjLst->GetObject( i );
1462 if ( pWin->IsVisible()) {
1463 if (( pWin->mnHeadDist + pWin->mnRootDist ) == nRetVal )
1465 if ( !LevelList[ pWin->mnHeadDist ] )
1466 LevelList[ pWin->mnHeadDist ] = new ObjWinList;
1467 LevelList[ pWin->mnHeadDist ]->Insert( pWin );
1468 LevelUse[ pWin->mnHeadDist ]++;
1470 else
1471 if ( pWin->mbVisited )
1473 if ( !LevelSecList[ nRetVal - pWin->mnRootDist ] )
1474 LevelSecList[ nRetVal - pWin->mnRootDist ] = new ObjWinList;
1475 LevelSecList[ nRetVal - pWin->mnRootDist ]->Insert( pWin );
1476 LevelSecUse[ nRetVal - pWin->mnRootDist ]++;
1478 else
1480 // need to be arranged more intelligent...
1481 Point aPos( 5, nUnvisYOffs );
1482 pWin->SetCalcPosPixel( aPos );
1484 Point aTmpPos = pWin->GetCalcPosPixel();
1485 pWin->SetPosPixel( mpBaseWin->LogicToPixel( aTmpPos ));
1487 nUnvisYOffs += pWin->PixelToLogic( pWin->GetSizePixel()).Height();
1488 nUnvisited++;
1493 mnLevelOffset = 0;
1495 USHORT nScaleVal;
1497 if ( nRetVal == 0 )
1498 nScaleVal = 1;
1499 else
1500 nScaleVal = nRetVal;
1502 i = 0;
1504 USHORT nStep = 0;
1506 while ( LevelList[ i ] )
1508 UpdateMainProgressBar(i, nScaleVal, nStep);
1509 DBG_ASSERT( LevelUse[ i ] == LevelList[ i ]->Count() , "level index im a..." );
1510 ObjectWin* pSwapWin;
1511 ULONG nLevelObjCount = LevelList[ i ]->Count();
1513 if ( nLevelObjCount % 2 == 0 )
1515 LevelList[ i ]->Insert( NULL, LIST_APPEND );
1516 nLevelObjCount++;
1517 // LevelUse bleibt orginal...
1518 // LevelUse[ i ]++;
1521 // catch too big lists
1522 DBG_ASSERT( nLevelObjCount < DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH , "graph zu breit! dat geiht nich gut. breaking" );
1523 if ( nLevelObjCount >= DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH )
1525 WarningBox aWBox( mpBaseWin, WB_OK, String::CreateFromAscii("graph zu breit! dat geiht nich gut. breaking"));
1526 aWBox.Execute();
1527 break;
1529 mnXOffset = CalcXOffset( nLevelObjCount );
1530 aWorkList.Clear();
1532 // initial positioning for mainstream
1533 for ( j = 0; j < nLevelObjCount; j++ )
1535 pSwapWin = LevelList[ i ]->GetObject( j );
1536 aWorkList.Insert( pSwapWin, LIST_APPEND);
1537 Point aPos = CalcPos( i, j );
1538 aPosArray[ j ] = aPos;
1539 if ( pSwapWin )
1540 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1543 double dMinDist = CalcDistSum( LevelList[ i ] );
1545 // optimize mainstream order and return best matching list in "aWorkList"
1546 dMinDist = MIN( dMinDist, Impl_PermuteMin( *(LevelList[ i ]), aPosArray, aWorkList, dMinDist, 0, nLevelObjCount ));
1548 // set optimized positions - may still be wrong from later tries
1549 for ( j = 0; j < nLevelObjCount; j++ )
1551 pSwapWin = aWorkList.GetObject( j );
1552 if ( pSwapWin )
1553 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1556 if ( LevelSecList[ i ] != NULL )
1558 ULONG nLevelSecObjCount = LevelSecList[ i ]->Count();
1559 // expand list for better positioning
1560 while ( nLevelSecObjCount + LevelUse[ i ] < DEPPER_MAX_WIDTH - 1 )
1562 LevelSecList[ i ]->Insert( NULL, LIST_APPEND );
1563 nLevelSecObjCount++;
1565 if ( ( nLevelSecObjCount + LevelUse[ i ])% 2 == 0 )
1567 LevelSecList[ i ]->Insert( NULL, LIST_APPEND );
1568 nLevelSecObjCount++;
1571 DBG_ASSERT( nLevelSecObjCount < DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH , "graph zu breit! dat geiht nich gut. breaking" );
1572 if ( nLevelObjCount >= DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH )
1574 WarningBox aWBox( mpBaseWin, WB_OK, String::CreateFromAscii("graph zu breit! dat geiht nich gut. breaking"));
1575 aWBox.Execute();
1576 break;
1578 mnXOffset = CalcXOffset( LevelUse[ i ] + nLevelSecObjCount );
1579 aWorkList.Clear();
1581 l = 0;
1582 BOOL bUsedPos;
1584 // find free positions for secondary objects
1585 for ( j = 0; j < ( LevelUse[ i ] + nLevelSecObjCount ) ; j++ )
1587 Point aPos = CalcPos( i, j );
1588 bUsedPos = FALSE;
1589 // is already occupied?
1590 for ( k = 0; k < nLevelObjCount; k++ )
1592 if ( LevelList[ i ]->GetObject( k ) )
1593 if ( aPos == LevelList[ i ]->GetObject( k )->GetCalcPosPixel() )
1594 bUsedPos = TRUE;
1596 // if its free, add to pool
1597 if ( !bUsedPos )
1599 aPosArray[ l ] = aPos;
1600 l++;
1604 // initial positioning for secodaries
1605 for ( j = 0 ; j < nLevelSecObjCount ; j++ )
1607 pSwapWin = LevelSecList[ i ]->GetObject( j );
1608 aWorkList.Insert( pSwapWin, LIST_APPEND);
1609 if ( pSwapWin )
1610 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1612 dMinDist = CalcDistSum( LevelSecList[ i ] );
1614 dMinDist = MIN( dMinDist, Impl_PermuteMin( *(LevelSecList[ i ]), aPosArray, aWorkList, dMinDist, 0, nLevelSecObjCount ));
1616 // set optimized positions - may still be wrong from later tries
1617 for ( j = 0; j < nLevelSecObjCount; j++ )
1619 pSwapWin = aWorkList.GetObject( j );
1620 if ( pSwapWin )
1621 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1623 if ( LevelUse[ i ] + LevelSecUse[ i ] > DEPPER_MAX_WIDTH )
1624 mnLevelOffset++;
1626 if ( LevelUse[ i ] + LevelSecUse[ i ] > DEPPER_MAX_WIDTH )
1627 mnLevelOffset+= ( LevelUse[ i ] + LevelSecUse[ i ] ) / DEPPER_MAX_WIDTH ;
1628 i++;
1631 mnMinDynXOffs = 0xffff;
1633 // and back again...
1634 // get better results form already preoptimized upper and lower rows
1638 i--;
1639 UpdateMainProgressBar(i, nScaleVal, nStep, TRUE); // TRUE ~ counting down
1640 if ( LevelUse[ i ] + LevelSecUse[ i ] > DEPPER_MAX_WIDTH )
1641 mnLevelOffset-= ( LevelUse[ i ] + LevelSecUse[ i ] ) / DEPPER_MAX_WIDTH ;
1642 ObjectWin* pSwapWin;
1643 ULONG nLevelObjCount = LevelList[ i ]->Count();
1644 mnXOffset = CalcXOffset( nLevelObjCount );
1645 aWorkList.Clear();
1647 for ( j = 0; j < nLevelObjCount; j++ )
1649 pSwapWin = LevelList[ i ]->GetObject( j );
1650 aWorkList.Insert( pSwapWin, LIST_APPEND);
1651 Point aPos = CalcPos( i, j );
1652 aPosArray[ j ] = aPos;
1653 //no need to do this stuff....... ?????
1654 if ( pSwapWin )
1655 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1658 double dMinDist = CalcDistSum( LevelList[ i ], BOTH );
1660 dMinDist = MIN( dMinDist, Impl_PermuteMin( *(LevelList[ i ]), aPosArray, aWorkList, dMinDist, 0, nLevelObjCount, BOTH ));
1661 // wrong position for remaping - keep old positions for comparing
1662 for ( j = 0; j < nLevelObjCount; j++ )
1664 pSwapWin = aWorkList.GetObject( j );
1665 if ( pSwapWin )
1666 // pSwapWin->SetCalcPosPixel( mpBaseWin->LogicToPixel( aPosArray[ j ] ));
1667 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1670 if ( LevelSecList[ i ] != NULL )
1672 ULONG nLevelSecObjCount = LevelSecList[ i ]->Count();
1673 mnXOffset = CalcXOffset( LevelUse[ i ] + nLevelSecObjCount );
1674 aWorkList.Clear();
1676 l = 0;
1677 BOOL bUsedPos;
1679 for ( j = 0; j < ( LevelUse[ i ] + nLevelSecObjCount ) ; j++ )
1681 Point aPos = CalcPos( i, j );
1682 bUsedPos = FALSE;
1683 // could be faster
1684 for ( k = 0; k < nLevelObjCount; k++ )
1686 if ( LevelList[ i ]->GetObject( k ) )
1687 if ( aPos == LevelList[ i ]->GetObject( k )->GetCalcPosPixel() )
1688 bUsedPos = TRUE;
1690 if ( !bUsedPos )
1692 aPosArray[ l ] = aPos;
1693 l++;
1697 for ( j = 0 ; j < nLevelSecObjCount ; j++ )
1699 pSwapWin = LevelSecList[ i ]->GetObject( j );
1700 aWorkList.Insert( pSwapWin, LIST_APPEND);
1701 if ( pSwapWin )
1702 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1704 dMinDist = CalcDistSum( LevelSecList[ i ], BOTH );
1706 dMinDist = MIN( dMinDist, Impl_PermuteMin( *(LevelSecList[ i ]), aPosArray, aWorkList, dMinDist, 0, nLevelSecObjCount, BOTH ));
1707 // wrong position for remaping - keep old positions for comparing
1708 for ( j = 0; j < nLevelSecObjCount; j++ )
1710 pSwapWin = aWorkList.GetObject( j );
1711 if ( pSwapWin )
1712 pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1715 // i--;
1716 } while ( i != 0 );
1717 SetMainProgressBar( 100 );
1719 ULONG nNewXSize = ( DEPPER_MAX_WIDTH + 1 ) * ( OBJWIN_X_SPACING + GetDefSize().Width() );
1721 // ULONG aObjID = GetStart(pIdMapper, pObjLst) //hier muß man switchen GetStart/GetPrjStart oder so
1723 ObjectWin* pObjWin = ObjIdToPtr( pObjLst, aObjID);
1725 ULONG nNewYSize = pObjWin->GetCalcPosPixel().Y() + GetDefSize().Height() + 2 * OBJWIN_Y_SPACING;
1726 if (( nUnvisYOffs + GetDefSize().Height()) > nNewYSize )
1727 nNewYSize = nUnvisYOffs + GetDefSize().Height();
1729 MapMode aMapMode = GetDepWin()->GetMapMode();
1730 Size aTmpSize( (ULONG) (double(nNewXSize) * double( aMapMode.GetScaleX())), (ULONG) (double( nNewYSize) * double( aMapMode.GetScaleY())));
1732 Size aNowSize( GetGraphWin()->GetSizePixel());
1734 if ( GetDepWin()->LogicToPixel( aNowSize ).Width() > aTmpSize.Width() )
1735 aTmpSize.Width() = GetDepWin()->LogicToPixel( aNowSize ).Width() ;
1737 if ( GetDepWin()->LogicToPixel( aNowSize ).Height() > aTmpSize.Height() )
1738 aTmpSize.Height() = GetDepWin()->LogicToPixel( aNowSize ).Height() ;
1740 // if ( nZoomed <= 0 )
1741 // {
1742 // mpBaseWin->SetSizePixel( aTmpSize );
1743 // mpGraphWin->SetTotalSize( aTmpSize );
1744 // mpGraphWin->EndScroll( 0, 0 );
1745 // }
1747 // now remap all objects
1748 ULONG nAllObjCount = pObjLst->Count();
1749 Point aTmpPos;
1750 for ( j = 0; j < nAllObjCount; j++ )
1752 pWin = pObjLst->GetObject( j );
1753 if ( pWin->IsVisible()) {
1754 aTmpPos = pWin->GetCalcPosPixel();
1755 if ( pWin->mbVisited )
1757 // reserve space for unconnected
1758 aTmpPos.X() -= mnMinDynXOffs;
1759 aTmpPos.X() += GetDefSize().Width() + OBJWIN_X_SPACING;
1760 // center window
1761 aTmpPos.X() += GetDefSize().Width() / 2;
1762 aTmpPos.X() -= pWin->PixelToLogic( pWin->GetSizePixel()).Width() / 2 ;
1764 pWin->SetPosPixel( GetDepWin()->LogicToPixel( aTmpPos ));
1767 aWorkList.Clear();
1768 GetDepWin()->EnablePaint( TRUE );
1769 GetDepWin()->Invalidate();
1770 //LevelListen loeschen Hä? Welche Levellisten?
1772 //Update all Connectors
1773 // --> To be done: Don't call twice Object1-Connector-Object2
1774 ObjectWin* pObject1;
1775 for ( i = 0 ; i < nObjCount ; i++)
1777 pObject1 = pObjLst->GetObject( i );
1778 if ( pObject1->IsVisible())
1779 pObject1->UpdateConnectors();
1781 return 0;
1784 void SolDep::WriteToErrorFile()
1786 //Needs some improvement
1787 ObjectWin* pWin;
1788 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"));
1789 aWBox.Execute();
1790 char *tmpdir = getenv("TMP");
1791 char *errfilebasename = "depper.err";
1792 char *ErrFileName = (char*) malloc( strlen( tmpdir ) + strlen( errfilebasename) + 3 );
1793 *ErrFileName = '\0';
1794 strcat( ErrFileName, tmpdir );
1795 strcat( ErrFileName, "\\" );
1796 strcat( ErrFileName, errfilebasename );
1797 FILE* pErrFile = fopen( "depper.err", "w+" );
1798 if ( pErrFile )
1800 for ( USHORT i = 0; i < mpTravellerList->Count(); i++ )
1802 pWin = mpTravellerList->GetObject( i );
1803 fprintf( pErrFile, " %s -> \n", (pWin->GetBodyText()).GetBuffer());
1805 fclose( pErrFile );