Changeset 446 for cafu/trunk

Show
Ignore:
Timestamp:
12/19/11 11:28:57 (5 months ago)
Author:
Carsten
Message:

CaWE: In MorphPrimT, replace member MapElementT* m_MapElem with more appropriate MapPrimitiveT* m_MapPrim.

Location:
cafu/trunk/CaWE
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/MapCommands/Morph.cpp

    r285 r446  
    2323 
    2424#include "../MapDocument.hpp" 
    25 #include "../MapElement.hpp" 
     25#include "../MapPrimitive.hpp" 
    2626#include "../MorphPrim.hpp" 
    2727 
     
    3333{ 
    3434    for (unsigned long i=0; i<MorphPrims.Size(); i++) 
    35         m_OldStates.PushBack(MorphPrims[i]->GetElem()->Clone()); 
     35        m_OldStates.PushBack(MorphPrims[i]->GetMapPrim()->Clone()); 
    3636} 
    3737 
     
    5959    for (unsigned long i=0; i<m_MorphPrims.Size(); i++) 
    6060    { 
    61         MorphPrimT*  MorphPrim=m_MorphPrims[i]; 
    62         MapElementT* MapElem  =m_MorphPrims[i]->GetElem(); 
     61        MorphPrimT*    MorphPrim=m_MorphPrims[i]; 
     62        MapPrimitiveT* MapPrim  =m_MorphPrims[i]->GetMapPrim(); 
    6363 
    64         OldBounds.PushBack(MapElem->GetBB()); 
     64        OldBounds.PushBack(MapPrim->GetBB()); 
    6565 
    66         if (!MorphPrim->ApplyMorphToMapElem()) 
     66        if (!MorphPrim->ApplyMorphToMapPrim()) 
    6767        { 
    6868            // Note that we cannot veto ("return;") here, not even in case of conversion failure. 
     
    7171        } 
    7272 
    73         UpdateObjects.PushBack(MapElem); 
     73        UpdateObjects.PushBack(MapPrim); 
    7474    } 
    7575 
     
    9292    for (unsigned long i=0; i<m_MorphPrims.Size(); i++) 
    9393    { 
    94         MapElementT* MapElem=m_MorphPrims[i]->GetElem(); 
     94        MapPrimitiveT* MapPrim=m_MorphPrims[i]->GetMapPrim(); 
    9595 
    96         OldBounds.PushBack(MapElem->GetBB()); 
     96        OldBounds.PushBack(MapPrim->GetBB()); 
    9797 
    98         MapElem->Assign(m_OldStates[i]); 
     98        MapPrim->Assign(m_OldStates[i]); 
    9999 
    100         UpdateObjects.PushBack(MapElem); 
     100        UpdateObjects.PushBack(MapPrim); 
    101101    } 
    102102 
  • cafu/trunk/CaWE/MapCommands/Morph.hpp

    r292 r446  
    2727 
    2828class MapDocumentT; 
    29 class MapElementT; 
     29class MapPrimitiveT; 
    3030class MorphPrimT; 
    3131 
     
    4848    MapDocumentT&             m_MapDoc; 
    4949    const ArrayT<MorphPrimT*> m_MorphPrims; 
    50     ArrayT<MapElementT*>      m_OldStates; 
     50    ArrayT<MapPrimitiveT*>    m_OldStates; 
    5151}; 
    5252 
  • cafu/trunk/CaWE/MorphPrim.cpp

    r285 r446  
    3333#include "Math3D/Polygon.hpp" 
    3434 
    35 #if defined(_WIN32) && defined(_MSC_VER) 
    36     #if (_MSC_VER<1300) 
    37         #define for if (false) ; else for 
    38     #endif 
    39 #endif 
    40  
    4135 
    4236MP_EdgeT::MP_EdgeT() 
     
    5044 
    5145 
    52 MorphPrimT::MorphPrimT(MapElementT* MapElem) 
    53     : m_MapElem(MapElem), 
     46MorphPrimT::MorphPrimT(MapPrimitiveT* MapPrim) 
     47    : m_MapPrim(MapPrim), 
    5448      m_Modified(false) 
    5549{ 
    56     MapBrushT*       MapBrush=dynamic_cast<MapBrushT*>      (m_MapElem); 
    57     MapBezierPatchT* MapPatch=dynamic_cast<MapBezierPatchT*>(m_MapElem); 
     50    MapBrushT*       MapBrush=dynamic_cast<MapBrushT*>      (m_MapPrim); 
     51    MapBezierPatchT* MapPatch=dynamic_cast<MapBezierPatchT*>(m_MapPrim); 
    5852 
    5953    wxASSERT(MapBrush!=NULL || MapPatch!=NULL);     // Assert they are not both NULL. 
     
    10599 
    106100 
    107 bool MorphPrimT::ApplyMorphToMapElem() 
    108 { 
    109     MapBrushT*       MapBrush=dynamic_cast<MapBrushT*>      (m_MapElem); 
    110     MapBezierPatchT* MapPatch=dynamic_cast<MapBezierPatchT*>(m_MapElem); 
     101bool MorphPrimT::ApplyMorphToMapPrim() 
     102{ 
     103    MapBrushT*       MapBrush=dynamic_cast<MapBrushT*>      (m_MapPrim); 
     104    MapBezierPatchT* MapPatch=dynamic_cast<MapBezierPatchT*>(m_MapPrim); 
    111105 
    112106    wxASSERT(MapBrush!=NULL || MapPatch!=NULL);     // Assert they are not both NULL. 
     
    388382    m_Modified=true; 
    389383 
    390     if (m_MapElem->GetType()==&MapBezierPatchT::TypeInfo) UpdatePatch(); 
    391     if (m_MapElem->GetType()==      &MapBrushT::TypeInfo) UpdateBrushFromVertices(); 
     384    if (m_MapPrim->GetType()==&MapBezierPatchT::TypeInfo) UpdatePatch(); 
     385    if (m_MapPrim->GetType()==      &MapBrushT::TypeInfo) UpdateBrushFromVertices(); 
    392386} 
    393387 
     
    395389void MorphPrimT::UpdateBrushFromVertices() 
    396390{ 
    397     if (dynamic_cast<MapBrushT*>(m_MapElem)==NULL) return; 
     391    if (dynamic_cast<MapBrushT*>(m_MapPrim)==NULL) return; 
    398392 
    399393    const float Epsilon=0.1f; 
     
    525519void MorphPrimT::UpdatePatch() 
    526520{ 
    527     MapBezierPatchT* MapPatch=(MapBezierPatchT*)m_MapElem; 
     521    MapBezierPatchT* MapPatch=(MapBezierPatchT*)m_MapPrim; 
    528522 
    529523    for (unsigned long y=0; y<MapPatch->GetHeight(); y++) 
  • cafu/trunk/CaWE/MorphPrim.hpp

    r285 r446  
    2929class MapBezierPatchT; 
    3030class MapBrushT; 
    31 class MapElementT; 
     31class MapPrimitiveT; 
    3232class Renderer2DT; 
    3333class Renderer3DT; 
     
    101101 
    102102    /// The constructor. 
    103     /// @param MapElem   The original brush or bezier patch that this MorphPrimT is associated with / attached to. 
    104     /// Note that this MorphPrimT does not become the "owner" of the MapElem pointer, e.g. it does not attempt to delete it in its dtor. 
    105     /// That also means that this MorphPrimT should not live longer than the MapElem object. 
    106     MorphPrimT(MapElementT* MapElem); 
     103    /// @param MapPrim   The original brush or bezier patch that this MorphPrimT is associated with / attached to. 
     104    /// Note that this MorphPrimT does not become the "owner" of the MapPrim pointer, e.g. it does not attempt to delete it in its dtor. 
     105    /// That also means that this MorphPrimT should not live longer than the MapPrim object. 
     106    MorphPrimT(MapPrimitiveT* MapPrim); 
    107107 
    108108    ~MorphPrimT(); 
    109109 
    110     MapElementT* GetElem() const { return m_MapElem; } 
    111     bool         IsModified() const { return m_Modified; } 
     110    MapPrimitiveT* GetMapPrim() const { return m_MapPrim; } 
     111    bool           IsModified() const { return m_Modified; } 
    112112 
    113113    /// Updates the associated map element by applying the morphed geometry to it. 
    114114    /// @returns if the update was successful. 
    115     bool ApplyMorphToMapElem(); 
     115    bool ApplyMorphToMapPrim(); 
    116116 
    117117    /// Moves the selected handles by Delta. 
     
    135135    /// After a change of (or in) the m_Vertices array, this method computes the convex hull over them 
    136136    /// and updates (or rather, recomputes) all other member variables (the m_Edges and m_Faces). 
    137     /// This method should only be called if the m_MapElem member is of type MapBrushT, 
     137    /// This method should only be called if the m_MapPrim member is of type MapBrushT, 
    138138    /// because it also modifies the m_Vertices array, which is not desired for the MapBezierPatchT type. 
    139139    void UpdateBrushFromVertices(); 
     
    147147 
    148148 
    149     MapElementT*        m_MapElem;  ///< The "attached" map brush / bezier patch. 
     149    MapPrimitiveT*      m_MapPrim;  ///< The "attached" map brush / bezier patch. 
    150150    bool                m_Modified; ///< Whether the MorphPrimT contains any modifications to the "attached" map brush/bezier patch. 
    151151}; 
  • cafu/trunk/CaWE/ToolMorph.cpp

    r444 r446  
    143143        // For each brush or bezier patch in the documents selection, create a related instance here. 
    144144        for (unsigned long SelNr=0; SelNr<m_MapDoc.GetSelection().Size(); SelNr++) 
    145             MorphPrims_ToggleElem(m_MapDoc.GetSelection()[SelNr]); 
     145        { 
     146            MapPrimitiveT* MapPrim=dynamic_cast<MapPrimitiveT*>(m_MapDoc.GetSelection()[SelNr]); 
     147 
     148            if (MapPrim) 
     149                MorphPrims_TogglePrim(MapPrim); 
     150        } 
    146151    } 
    147152} 
     
    163168{ 
    164169    for (unsigned long MPNr=0; MPNr<m_MorphPrims.Size(); MPNr++) 
    165         if (m_MorphPrims[MPNr]->GetElem()==Elem) 
     170        if (m_MorphPrims[MPNr]->GetMapPrim()==Elem) 
    166171            return MPNr; 
    167172 
     
    180185        if (!m_MorphPrims[MPNr]->IsModified()) 
    181186        { 
    182             UnmodifiedMapElems.PushBack(m_MorphPrims[MPNr]->GetElem()); 
     187            UnmodifiedMapElems.PushBack(m_MorphPrims[MPNr]->GetMapPrim()); 
    183188 
    184189            delete m_MorphPrims[MPNr]; 
     
    208213 
    209214 
    210 void ToolMorphT::MorphPrims_ToggleElem(MapElementT* Elem) 
     215void ToolMorphT::MorphPrims_TogglePrim(MapPrimitiveT* MapPrim) 
    211216{ 
    212217    // Only needed for observer message. 
    213218    ArrayT<MapElementT*> MapElements; 
    214     MapElements.PushBack(Elem); 
    215  
    216     const int MP_Index=MorphPrims_Find(Elem); 
     219    MapElements.PushBack(MapPrim); 
     220 
     221    const int MP_Index=MorphPrims_Find(MapPrim); 
    217222 
    218223    if (MP_Index>=0) 
     
    244249    } 
    245250 
    246     if (dynamic_cast<MapBrushT*>(Elem)==NULL && dynamic_cast<MapBezierPatchT*>(Elem)==NULL) return; 
    247  
    248     MorphPrimT* MorphPrim=new MorphPrimT(Elem); 
     251    if (dynamic_cast<MapBrushT*>(MapPrim)==NULL && dynamic_cast<MapBezierPatchT*>(MapPrim)==NULL) return; 
     252 
     253    MorphPrimT* MorphPrim=new MorphPrimT(MapPrim); 
    249254    m_MorphPrims.PushBack(MorphPrim); 
    250255 
     
    457462    } 
    458463 
    459     if (dynamic_cast<MapBrushT*>(m_MorphPrims[0]->GetElem())==NULL) 
     464    if (dynamic_cast<MapBrushT*>(m_MorphPrims[0]->GetMapPrim())==NULL) 
    460465    { 
    461466        wxMessageBox("The morph tool can add new vertices only to brushes (not to Bezier patches).\n" 
     
    617622    for (unsigned long HitNr=0; HitNr<HitElems.Size(); HitNr++) 
    618623    { 
    619         if (HitElems[HitNr]->GetType()==&MapBrushT::TypeInfo || HitElems[HitNr]->GetType()==&MapBezierPatchT::TypeInfo) 
     624        MapPrimitiveT* HitPrim=dynamic_cast<MapPrimitiveT*>(HitElems[HitNr]); 
     625 
     626        if (HitPrim && (HitPrim->GetType()==&MapBrushT::TypeInfo || HitPrim->GetType()==&MapBezierPatchT::TypeInfo)) 
    620627        { 
    621628            if (!ME.ControlDown()) MorphPrims_CommitAndClear(); 
    622             MorphPrims_ToggleElem(HitElems[HitNr]); 
     629            MorphPrims_TogglePrim(HitPrim); 
    623630 
    624631            m_ToolMan.UpdateAllObservers(this, UPDATE_NOW); 
     
    885892    if (HitElems.Size()>0)      // Only consider the nearest hit, if any. 
    886893    { 
    887         if (HitElems[0].Object->GetType()==&MapBrushT::TypeInfo || HitElems[0].Object->GetType()==&MapBezierPatchT::TypeInfo) 
     894        MapPrimitiveT* HitPrim=dynamic_cast<MapPrimitiveT*>(HitElems[0].Object); 
     895 
     896        if (HitPrim && (HitPrim->GetType()==&MapBrushT::TypeInfo || HitPrim->GetType()==&MapBezierPatchT::TypeInfo)) 
    888897        { 
    889898            if (!ME.ControlDown()) MorphPrims_CommitAndClear(); 
    890             MorphPrims_ToggleElem(HitElems[0].Object); 
     899            MorphPrims_TogglePrim(HitPrim); 
    891900 
    892901            m_ToolMan.UpdateAllObservers(this, UPDATE_NOW); 
     
    10321041    for (unsigned long i=0; i<MapElements.Size(); i++) 
    10331042    { 
     1043        MapPrimitiveT* MapPrim=dynamic_cast<MapPrimitiveT*>(MapElements[i]); 
     1044 
     1045        if (!MapPrim) continue; 
     1046 
    10341047        for (unsigned long j=0; j<m_MorphPrims.Size(); j++) 
    10351048        { 
    1036             if (MapElements[i]==m_MorphPrims[j]->GetElem()) 
     1049            if (MapPrim==m_MorphPrims[j]->GetMapPrim()) 
    10371050            { 
    10381051                // Remove this morph primitive from our list. 
     
    10571070    for (unsigned long i=0; i<MapElements.Size(); i++) 
    10581071    { 
     1072        MapPrimitiveT* MapPrim=dynamic_cast<MapPrimitiveT*>(MapElements[i]); 
     1073 
     1074        if (!MapPrim) continue; 
     1075 
    10591076        for (unsigned long j=0; j<m_MorphPrims.Size(); j++) 
    10601077        { 
    1061             if (MapElements[i]==m_MorphPrims[j]->GetElem()) 
     1078            if (MapPrim==m_MorphPrims[j]->GetMapPrim()) 
    10621079            { 
    10631080                // Update the morph primitive of this map element, discarding all prior changes, if any. 
    10641081                delete m_MorphPrims[j]; 
    1065                 m_MorphPrims[j]=new MorphPrimT(MapElements[i]); 
     1082                m_MorphPrims[j]=new MorphPrimT(MapPrim); 
    10661083 
    10671084                // Object has been found so we can safely break the inner loop and check the next object. 
     
    10821099    for (unsigned long i=0; i<MapElements.Size(); i++) 
    10831100    { 
     1101        MapPrimitiveT* MapPrim=dynamic_cast<MapPrimitiveT*>(MapElements[i]); 
     1102 
     1103        if (!MapPrim) continue; 
     1104 
    10841105        for (unsigned long j=0; j<m_MorphPrims.Size(); j++) 
    10851106        { 
    1086             if (MapElements[i]==m_MorphPrims[j]->GetElem()) 
     1107            if (MapPrim==m_MorphPrims[j]->GetMapPrim()) 
    10871108            { 
    10881109                // Update the morph primitive of this map element, discarding all prior changes, if any. 
    10891110                delete m_MorphPrims[j]; 
    1090                 m_MorphPrims[j]=new MorphPrimT(MapElements[i]); 
     1111                m_MorphPrims[j]=new MorphPrimT(MapPrim); 
    10911112 
    10921113                // Object has been found so we can safely break the inner loop and check the next object. 
  • cafu/trunk/CaWE/ToolMorph.hpp

    r285 r446  
    117117    int  MorphPrims_Find(const MapElementT* Elem) const;    ///< Returns the array index number of the MorphPrimT for the given Elem, -1 if there is none. 
    118118    void MorphPrims_CommitAndClear();                       ///< Commits all morphs in m_MorphPrims to their true map elements and resets the morph tool back to empty. 
    119     void MorphPrims_ToggleElem(MapElementT* Elem);          ///< Toggles the membership of Elem in the m_MorphPrims array. 
     119    void MorphPrims_TogglePrim(MapPrimitiveT* MapPrim);     ///< Toggles the membership of MapPrim in the m_MorphPrims array. 
    120120    void MoveSelectedHandles(const Vector3fT& Delta);       ///< WARNING: This method *DESTROYS* all handle pointers into any of the m_MorphPrims!! 
    121121    void NudgeSelectedHandles(const AxesInfoT& AxesInfo, const wxKeyEvent& KE);