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>
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("#==========================================================================");
59 /*****************************************************************************/
60 SolDep::SolDep( Window
* pBaseWindow
)
61 /*****************************************************************************/
62 : Depper( pBaseWindow
),
64 mpTravellerList( NULL
),
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
));
76 mpBaseWin
->AddChildEventListener( LINK( this, SolDep
, ChildWindowEventListener
));
78 // Kontext-Menue (gehört zu soldep.cxx)
79 InitContextMenueMainWnd();
80 InitContextMenuePrjViewWnd( mpBasePrjWin
);
83 /*****************************************************************************/
85 /*****************************************************************************/
87 mpBaseWin
->RemoveChildEventListener( LINK( this, SolDep
, ChildWindowEventListener
) );
93 /*****************************************************************************/
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") ) {
106 ReadSource(); // if stand.lst isn't available
110 /*****************************************************************************/
111 void SolDep::Init( ByteString
&rVersion
, GenericInformationList
*pVersionList
)
112 /*****************************************************************************/
117 mpStandLst
= new GenericInformationList( *pVersionList
);
119 InformationParser aParser
;
120 String
sStandLst( GetDefStandList(), RTL_TEXTENCODING_ASCII_US
);
121 mpStandLst
= aParser
.Execute( sStandLst
);
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
) );
141 /*****************************************************************************/
142 void SolDep::ProcessChildWindowEvent( const VclWindowEvent
& _rVclWindowEvent
)
143 /*****************************************************************************/
145 Window
* pChildWin
= _rVclWindowEvent
.GetWindow();
146 // Window* pParentWin = pChildWin->GetParent();
150 ULONG id
= _rVclWindowEvent
.GetId();
153 case VCLEVENT_USER_MOUSEBUTTON_DOWN
:
155 ObjectWin
* pObjWin
= dynamic_cast<ObjectWin
*>(pChildWin
);
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
);
166 pWin
->MarkDepending();
171 pWin
->SetMarkMode( MARKMODE_SELECTED
);
172 pWin
->UnsetMarkMode( MARKMODE_ACTIVATED
);
173 pWin
->MarkNeeded( TRUE
);
174 pWin
->MarkDepending( TRUE
);
180 case VCLEVENT_USER_MOUSEBUTTON_DOWN_ALT
:
182 ObjectWin
* pObjWin
= dynamic_cast<ObjectWin
*>(pChildWin
);
185 ObjectWin
* pWin
= (ObjectWin
*) pChildWin
;
190 case VCLEVENT_USER_MOUSEBUTTON_DOWN_DBLCLICK
:
192 ObjectWin
* pObjWin
= dynamic_cast<ObjectWin
*>(pChildWin
);
195 if (IsHideMode()) ToggleHideDependency();
196 ByteString text
= ((ObjectWin
*) pChildWin
)->GetBodyText();
201 case VCLEVENT_USER_MOUSEBUTTON_UP_SHFT
:
203 ObjectWin
* pObjWin
= dynamic_cast<ObjectWin
*>(pChildWin
);
206 ObjectWin
* pWin
= (ObjectWin
*) pChildWin
;
207 GetDepWin()->NewConnector( pWin
);
211 case VCLEVENT_USER_MOUSEBUTTON_UP
:
213 ObjectWin
* pObjWin
= dynamic_cast<ObjectWin
*>(pChildWin
);
216 ObjectWin
* pWin
= (ObjectWin
*) pChildWin
;
217 pWin
->ReleaseMouse();
218 pWin
->SetMarkMode(MARKMODE_SELECTED
);
219 GetDepWin()->Invalidate();
225 //fprintf(stdout,"BLA::Resize: %d\n",pChildWin);
228 /*****************************************************************************/
229 IMPL_LINK( SolDep
, ToolSelect
, SoldepToolBox
* , pBox
)
230 /*****************************************************************************/
232 USHORT nItemId
= pBox
->GetCurItemId();
235 case TID_SOLDEP_FIND
:
238 case TID_SOLDEP_CREATEMETA
:
241 aVDev
.SetMapMode( MAP_100TH_MM
);
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();
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
);
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
);
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
293 case TID_SOLDEP_SELECT_WORKSPACE
:
296 if (GetVersion()) // Version dialog box
298 delete mpSolIdMapper
;
300 mpObjectList
->ClearAndDelete();
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)
311 TogglePrjViewStatus();
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();
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 /*****************************************************************************/
369 //hshtable auf stand halten
370 ObjectWin
* pWin
= RemoveObjectFromList( mpObjectList
, mnSolWinCount
, nId
, FALSE
);
373 ByteString
aBodyText( pWin
->GetBodyText() );
374 if( (pPrj
= mpStarWriter
->GetPrj( aBodyText
)) )
376 mpStarWriter
->Remove( pPrj
);
377 //cleanup ist teuer...
378 mpStarWriter
->CleanUp();
382 DBG_ASSERT( FALSE
, "project not found - write" );
384 mpSolIdMapper
->Delete( aBodyText
);
393 /*****************************************************************************/
394 ULONG
SolDep::AddObject( ByteString
& rBodyText
, BOOL bInteract
)
395 /*****************************************************************************/
400 nObjectId
= HandleNewPrjDialog( rBodyText
);
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
);
413 /*****************************************************************************/
414 ULONG
SolDep::AddPrjObject( ByteString
& rBodyText
, BOOL bInteract
)
415 /*****************************************************************************/
420 nObjectId
= HandleNewDirectoryDialog( rBodyText
);
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
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
);
444 pPrj
->AddDependencies( sStartName
);
445 return AddConnectorToObjects( pStartWin
, pEndWin
);
449 DBG_ASSERT( FALSE
, "non existing Project" );
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
);
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
);
488 delete mpSolIdMapper
;
489 mpSolIdMapper
= NULL
;
498 /*****************************************************************************/
499 ULONG
SolDep::GetStart(SolIdMapper
* pIdMapper
, ObjectList
* pObjList
)
500 /*****************************************************************************/
502 // DBG_ASSERT( FALSE , "soldep" );
503 MyHashObject
* pHObject
= pIdMapper
->Find( "null" );//null_project
506 ByteString sNullPrj
= "null";//null_project
507 ULONG nObjectId
= AddObject( sNullPrj
, FALSE
);
508 ObjIdToPtr( pObjList
, nObjectId
)->SetViewMask( 1 );
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
523 ByteString
bsNull("null");
524 ULONG nObjectId
= AddPrjObject( bsNull
, FALSE
); //null_dir
528 return pHObject
->GetId();
531 /*****************************************************************************/
532 USHORT
SolDep::OpenSource()
533 /*****************************************************************************/
542 /*****************************************************************************/
543 USHORT
SolDep::ReadSource(BOOL bUpdater
)
544 /*****************************************************************************/
546 mpBaseWin
->EnablePaint( FALSE
);
548 ULONG nObjectId
, nHashedId
;
550 MyHashObject
* pHObject
;
552 ObjectWin
*pStartWin
, *pEndWin
;
554 mpSolIdMapper
= new SolIdMapper( 63997 );
555 if (mpStandLst
&& bUpdater
)
557 mpStarWriter
= new StarWriter( mpStandLst
, msVersionMajor
, msVersionMinor
, TRUE
);
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
);
590 ULONG nDepCount
= pLst
->Count();
591 for ( ULONG m
=0; m
<nDepCount
; m
++)
593 pStr
= pLst
->GetObject(m
);
594 pHObject
= mpSolIdMapper
->Find( *pStr
);
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 );
607 nHashedId
= pHObject
->GetId();
608 ByteString sF_Os2
= pPrj
->GetProjectName();
610 pHObject
= mpSolIdMapper
->Find( *pStr
);
611 nObjectId
= pHObject
->GetId();
612 pStartWin
= ObjIdToPtr( mpObjectList
, nHashedId
);
613 pEndWin
= ObjIdToPtr( mpObjectList
, nObjectId
);
614 AddConnectorToObjects( pStartWin
, pEndWin
);
621 AutoArrange( mpSolIdMapper
, mpObjectList
, GetStart(mpSolIdMapper
,mpObjectList
), 0, GetStart(mpSolIdMapper
,mpObjectList
) );
622 GetDepWin()->EnablePaint( TRUE
);
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
) );
635 Dir
aDir( aCurrent
, FSYS_KIND_DIR
);
637 USHORT nEntries
= aDir
.Count();
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
);
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() )
661 delete pSolarFileList
;
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 ) {
682 //String sRoot = mpStarWriter->GetSourceRoot();
683 //nicht mehr unterstützt mpStarWriter->GetSourceRoot()
684 ByteString sFileName = mpStarWriter->GetName();
685 DirEntry aEntry( sFileName );
687 aEntry = aEntry.GetPath().GetPath().GetPath();
688 String sRoot = aEntry.GetFull();
691 mpStarWriter->RemoveProject( ByteString( "null")); //null_project
692 mpStarWriter->WriteMultiple( sRoot );
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
);
706 ULONG nLoadOffs
= mnSolLastId
; //or Prj??
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());
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
);
744 /*****************************************************************************/
745 BOOL
SolDep::ViewContent( ByteString
& rObjectName
)
746 /*****************************************************************************/
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();
757 return InitPrj( rObjectName
);
760 /*****************************************************************************/
761 BOOL
SolDep::InitPrj( ByteString
& rListName
)
762 /*****************************************************************************/
764 ULONG nObjectId
, nHashedId
;
766 MyHashObject
* pHObject
;
767 ByteString
*pDepName
;
768 ByteString
*pFlagName
;
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();
778 mpObjectPrjList
->ClearAndDelete();
779 GetDepWin()->ClearConnectorList();
780 if (mpPrjIdMapper
) delete mpPrjIdMapper
;
781 mpPrjIdMapper
= new SolIdMapper( 63997 ); //generate clean mapper
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
)
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();
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, '.'));
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, '.'));
850 nHashedId
= pHObject
->GetId();
851 pStartWin
= ObjIdToPtr( mpObjectPrjList
, nHashedId
);
852 pEndWin
= ObjIdToPtr( mpObjectPrjList
, nObjectId
);
854 AddConnectorToObjects( pStartWin
, pEndWin
);
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
);
874 ByteString sNullDir
= "null";
875 nObjectId
= AddPrjObject( sNullDir
, FALSE
);
876 ObjectWin
*pWin
= ObjIdToPtr( mpObjectPrjList
, nObjectId
);
877 pWin
->SetViewMask( 0x0001 );
878 mpGraphPrjWin
->EnablePaint( TRUE
);
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
) );
884 mpGraphPrjWin
->Show();
885 mpGraphPrjWin
->Invalidate();
890 /*****************************************************************************/
891 USHORT
SolDep::CloseWindow()
892 /*****************************************************************************/
895 ((SystemWindow
*)mpProcessWin
)->Close();
899 /*****************************************************************************/
900 void SolDep::ShowHelp()
901 /*****************************************************************************/
903 SvFileStream
aHelpFile( String::CreateFromAscii( "g:\\soldep.hlp" ), STREAM_READ
);
907 if ( aHelpFile
.IsOpen() )
909 while ( aHelpFile
.ReadLine( aGetStr
) )
911 aHelpText
+= String (aGetStr
, RTL_TEXTENCODING_UTF8
);
912 aHelpText
+= String::CreateFromAscii("\n");
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
);
925 /*****************************************************************************/
926 BOOL
SolDep::FindProject()
927 /*****************************************************************************/
929 SolFindProjectDlg
aFindProjectDlg( GetDepWin(), GetObjectList() );
930 ObjectWin
* pObjectWin
= NULL
;
931 mpObjectList
->ResetSelectedObject();
934 GetDepWin()->Invalidate();
939 if ( aFindProjectDlg
.Execute() == RET_OK
) {
940 msProject
= aFindProjectDlg
.GetProject();
941 //now we have a project string
943 pObjectWin
= mpObjectList
->GetPtrByName( msProject
);
946 mpObjectList
->ResetSelectedObject();
947 MarkObjects( pObjectWin
);
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
);
963 BOOL
SolDep::MarkObjects( ObjectWin
* pObjectWin
)
967 if (!(pObjectWin
->IsNullObject()))
969 pObjectWin
->SetMarkMode( MARKMODE_SELECTED
);
970 pObjectWin
->MarkNeeded();
971 pObjectWin
->MarkDepending();
974 GetDepWin()->Invalidate();
978 fprintf(stdout
,"null\n");
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
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())
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())
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())
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())
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();
1083 GetGraphWin()->SetPosSizePixel(Point(0,0),aOutSize
);
1084 //if (IsPrjView() && (mpPrjDep)) mpPrjDep->Resize();
1085 if (maToolBox
.IsVisible()) maToolBox
.Show();
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();
1103 pDeps
->PutString( &sStartName
);
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();
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();
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
);
1153 ULONG
SolDep::CalcXOffset( ULONG nObjectsToFit
)
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
;
1173 double SolDep::CalcDistSum( ObjWinList
* pObjList
, DistType eDistType
)
1177 ULONG nObjCount
= pObjList
->Count();
1183 for ( i
= 0; i
< nObjCount
; i
++ )
1185 pWin
= pObjList
->GetObject( i
);
1187 if ( pWin
&& pWin
->IsVisible())
1191 while ( (pCon
= pWin
->GetConnector( j
)) )
1193 if ( pCon
->IsVisible()) {
1194 bIsStart
= pCon
->IsStart( pWin
);
1195 if ( eDistType
!= BOTH
)
1196 if ( eDistType
== TOPDOWN
)
1200 pCon
->UpdatePosition( pWin
, FALSE
);
1201 dWinVal
+= pCon
->GetLen() * pWin
->mnHeadDist
;
1208 pCon
->UpdatePosition( pWin
, FALSE
);
1209 dWinVal
+= pCon
->GetLen() * pWin
->mnRootDist
;
1215 pCon
->UpdatePosition( pWin
, FALSE
);
1217 dWinVal
+= pCon
->GetLen() * ( pWin
->mnHeadDist
+ 1 );
1219 dWinVal
+= pCon
->GetLen() * pWin
->mnRootDist
;
1233 USHORT
SolDep::Impl_Traveller( ObjectWin
* pWin
, USHORT 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!" );
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
;
1266 pWin
->mnHeadDist
= MAX( pWin
->mnHeadDist
, nMaxDepth
- nDepth
);
1271 double SolDep::Impl_PermuteMin( ObjWinList
& rObjList
, Point
* pPosArray
, ObjWinList
& rResultList
, double dMinDist
, ULONG nStart
, ULONG nSize
, DistType eDistType
)
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
));
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
);
1299 pSwapWin
->SetCalcPosPixel( pPosArray
[ nIdx2
] );
1300 pSwapWin
= rObjList
.Replace( pSwapWin
, nIdx2
);
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
);
1322 pSwapWin
->SetCalcPosPixel( pPosArray
[ nIdx2
] );
1323 pSwapWin
= rObjList
.Replace( pSwapWin
, nIdx2
);
1325 pSwapWin
->SetCalcPosPixel( pPosArray
[ nIdx1
] );
1326 rObjList
.Replace( pSwapWin
, nIdx1
);
1333 for ( i
= nStart
; i
< nEnd
; i
++)
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
);
1349 for ( l
= 0; l
< nLevelObjCount
; l
++ )
1351 pSwapWin
= rObjList
.GetObject( l
);
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
);
1377 USHORT
SolDep::OptimizePos(SolIdMapper
* pIdMapper
, ObjectList
* pObjLst
, ULONG nTopId
, ULONG nBottmId
, ULONG aObjID
)
1379 ObjWinList aWorkList
;
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
++ )
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
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
))
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
)
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
]++;
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
]++;
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();
1500 nScaleVal
= nRetVal
;
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
);
1517 // LevelUse bleibt orginal...
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"));
1529 mnXOffset
= CalcXOffset( nLevelObjCount
);
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
;
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
);
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"));
1578 mnXOffset
= CalcXOffset( LevelUse
[ i
] + nLevelSecObjCount
);
1584 // find free positions for secondary objects
1585 for ( j
= 0; j
< ( LevelUse
[ i
] + nLevelSecObjCount
) ; j
++ )
1587 Point aPos
= CalcPos( i
, j
);
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() )
1596 // if its free, add to pool
1599 aPosArray
[ l
] = aPos
;
1604 // initial positioning for secodaries
1605 for ( j
= 0 ; j
< nLevelSecObjCount
; j
++ )
1607 pSwapWin
= LevelSecList
[ i
]->GetObject( j
);
1608 aWorkList
.Insert( pSwapWin
, LIST_APPEND
);
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
);
1621 pSwapWin
->SetCalcPosPixel( aPosArray
[ j
] );
1623 if ( LevelUse
[ i
] + LevelSecUse
[ i
] > DEPPER_MAX_WIDTH
)
1626 if ( LevelUse
[ i
] + LevelSecUse
[ i
] > DEPPER_MAX_WIDTH
)
1627 mnLevelOffset
+= ( LevelUse
[ i
] + LevelSecUse
[ i
] ) / DEPPER_MAX_WIDTH
;
1631 mnMinDynXOffs
= 0xffff;
1633 // and back again...
1634 // get better results form already preoptimized upper and lower rows
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
);
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....... ?????
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
);
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
);
1679 for ( j
= 0; j
< ( LevelUse
[ i
] + nLevelSecObjCount
) ; j
++ )
1681 Point aPos
= CalcPos( i
, j
);
1684 for ( k
= 0; k
< nLevelObjCount
; k
++ )
1686 if ( LevelList
[ i
]->GetObject( k
) )
1687 if ( aPos
== LevelList
[ i
]->GetObject( k
)->GetCalcPosPixel() )
1692 aPosArray
[ l
] = aPos
;
1697 for ( j
= 0 ; j
< nLevelSecObjCount
; j
++ )
1699 pSwapWin
= LevelSecList
[ i
]->GetObject( j
);
1700 aWorkList
.Insert( pSwapWin
, LIST_APPEND
);
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
);
1712 pSwapWin
->SetCalcPosPixel( aPosArray
[ j
] );
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 )
1742 // mpBaseWin->SetSizePixel( aTmpSize );
1743 // mpGraphWin->SetTotalSize( aTmpSize );
1744 // mpGraphWin->EndScroll( 0, 0 );
1747 // now remap all objects
1748 ULONG nAllObjCount
= pObjLst
->Count();
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
;
1761 aTmpPos
.X() += GetDefSize().Width() / 2;
1762 aTmpPos
.X() -= pWin
->PixelToLogic( pWin
->GetSizePixel()).Width() / 2 ;
1764 pWin
->SetPosPixel( GetDepWin()->LogicToPixel( aTmpPos
));
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();
1784 void SolDep::WriteToErrorFile()
1786 //Needs some improvement
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"));
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+" );
1800 for ( USHORT i
= 0; i
< mpTravellerList
->Count(); i
++ )
1802 pWin
= mpTravellerList
->GetObject( i
);
1803 fprintf( pErrFile
, " %s -> \n", (pWin
->GetBodyText()).GetBuffer());