GME  13
AnnotatorCompositePart.cpp
Go to the documentation of this file.
00001 //################################################################################################
00002 //
00003 // New Annotator decorator composite part class
00004 //      AnnotatorCompositePart.cpp
00005 //
00006 //################################################################################################
00007 
00008 #include "StdAfx.h"
00009 #include "AnnotatorCompositePart.h"
00010 
00011 #include "AnnotatorRectanglePart.h"
00012 #include "AnnotatorTextPart.h"
00013 #include "DecoratorExceptions.h"
00014 
00015 
00016 namespace AnnotatorDecor {
00017 
00018 //################################################################################################
00019 //
00020 // CLASS : AnnotatorCompositePart
00021 //
00022 //################################################################################################
00023 
00024 AnnotatorCompositePart::AnnotatorCompositePart(DecoratorSDK::PartBase* pPart, CComPtr<IMgaCommonDecoratorEvents>& eventSink):
00025         ObjectAndTextPart(pPart, eventSink)
00026 {
00027 }
00028 
00029 AnnotatorCompositePart::~AnnotatorCompositePart()
00030 {
00031 }
00032 
00033 void AnnotatorCompositePart::SetParam(const CString& strName, VARIANT vValue)
00034 {
00035         m_strName = strName;
00036         m_vValue = vValue;
00037 }
00038 
00039 CSize AnnotatorCompositePart::GetPreferredSize(void) const
00040 {
00041         HRESULT retVal = S_OK;
00042         std::vector<PartBase*>::const_iterator ii = m_compositeParts.begin();
00043         if (m_compositeParts.size() > 1)
00044                 ++ii;   // we expect that the second part is the label if there's more than one part
00045         if (ii != m_compositeParts.end()) {
00046                 try {
00047                         return (*ii)->GetPreferredSize();
00048                 }
00049                 catch(hresult_exception& e) {
00050                         retVal = e.hr;
00051                 }
00052                 catch(DecoratorException& e) {
00053                         retVal = e.GetHResult();
00054                 }
00055         }
00056 
00057         throw DecoratorException((DecoratorExceptionCode)retVal);
00058 }
00059 
00060 CRect AnnotatorCompositePart::GetPortLocation(CComPtr<IMgaFCO>& fco) const
00061 {
00062         throw PortNotFoundException();
00063 }
00064 
00065 CRect AnnotatorCompositePart::GetLabelLocation(void) const
00066 {
00067         HRESULT retVal = S_OK;
00068         std::vector<PartBase*>::const_iterator ii = m_compositeParts.begin();
00069         if (m_compositeParts.size() > 1)
00070                 ++ii;   // we expect that the second part is the label if there's more than one part
00071         if (ii != m_compositeParts.end()) {
00072                 try {
00073                         return (*ii)->GetLabelLocation();
00074                 }
00075                 catch(hresult_exception& e) {
00076                         retVal = e.hr;
00077                 }
00078                 catch(DecoratorException& e) {
00079                         retVal = e.GetHResult();
00080                 }
00081         }
00082 
00083         throw DecoratorException((DecoratorExceptionCode)retVal);
00084 }
00085 
00086 // New functions
00087 void AnnotatorCompositePart::InitializeEx(CComPtr<IMgaProject>& pProject, CComPtr<IMgaMetaPart>& pPart, CComPtr<IMgaFCO>& pFCO,
00088                                                                                   HWND parentWnd, DecoratorSDK::PreferenceMap& preferences)
00089 {
00090         try {
00091                 if (pProject) {
00092                         AddObjectPart(new AnnotatorRectanglePart(this, m_eventSink));
00093                         AddTextPart(new AnnotatorTextPart(this, m_eventSink));
00094                 }
00095         }
00096         catch (hresult_exception& e) {
00097                 throw DecoratorException((DecoratorExceptionCode)e.hr);
00098         }
00099 
00100         PartBase::InitializeEx(pProject, pPart, pFCO, parentWnd, preferences);
00101         DecoratorSDK::TextPart* txtPart = GetTextPart();
00102         PartBase* objPart = GetObjectPart();
00103         txtPart->SetParam(m_strName, m_vValue);
00104         objPart->SetParam(m_strName, m_vValue);
00105         txtPart->InitializeEx(pProject, pPart, pFCO, parentWnd, preferences);
00106         objPart->InitializeEx(pProject, pPart, pFCO, parentWnd, preferences);
00107 }
00108 
00109 void AnnotatorCompositePart::InitializeEx(CComPtr<IMgaProject>& pProject, CComPtr<IMgaMetaPart>& pPart, CComPtr<IMgaFCO>& pFCO,
00110                                                                                   HWND parentWnd)
00111 {
00112         DecoratorSDK::getFacilities().loadPathes(pProject, true);
00113 
00114         DecoratorSDK::PreferenceMap preferencesMap;
00115         InitializeEx(pProject, pPart, pFCO, parentWnd, preferencesMap);
00116 }
00117 
00118 }; // namespace AnnotatorDecor