Changeset 446
- Timestamp:
- 12/19/11 11:28:57 (5 months ago)
- Location:
- cafu/trunk/CaWE
- Files:
-
- 6 modified
-
MapCommands/Morph.cpp (modified) (5 diffs)
-
MapCommands/Morph.hpp (modified) (2 diffs)
-
MorphPrim.cpp (modified) (6 diffs)
-
MorphPrim.hpp (modified) (4 diffs)
-
ToolMorph.cpp (modified) (11 diffs)
-
ToolMorph.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cafu/trunk/CaWE/MapCommands/Morph.cpp
r285 r446 23 23 24 24 #include "../MapDocument.hpp" 25 #include "../Map Element.hpp"25 #include "../MapPrimitive.hpp" 26 26 #include "../MorphPrim.hpp" 27 27 … … 33 33 { 34 34 for (unsigned long i=0; i<MorphPrims.Size(); i++) 35 m_OldStates.PushBack(MorphPrims[i]->Get Elem()->Clone());35 m_OldStates.PushBack(MorphPrims[i]->GetMapPrim()->Clone()); 36 36 } 37 37 … … 59 59 for (unsigned long i=0; i<m_MorphPrims.Size(); i++) 60 60 { 61 MorphPrimT* MorphPrim=m_MorphPrims[i];62 Map ElementT* MapElem =m_MorphPrims[i]->GetElem();61 MorphPrimT* MorphPrim=m_MorphPrims[i]; 62 MapPrimitiveT* MapPrim =m_MorphPrims[i]->GetMapPrim(); 63 63 64 OldBounds.PushBack(Map Elem->GetBB());64 OldBounds.PushBack(MapPrim->GetBB()); 65 65 66 if (!MorphPrim->ApplyMorphToMap Elem())66 if (!MorphPrim->ApplyMorphToMapPrim()) 67 67 { 68 68 // Note that we cannot veto ("return;") here, not even in case of conversion failure. … … 71 71 } 72 72 73 UpdateObjects.PushBack(Map Elem);73 UpdateObjects.PushBack(MapPrim); 74 74 } 75 75 … … 92 92 for (unsigned long i=0; i<m_MorphPrims.Size(); i++) 93 93 { 94 Map ElementT* MapElem=m_MorphPrims[i]->GetElem();94 MapPrimitiveT* MapPrim=m_MorphPrims[i]->GetMapPrim(); 95 95 96 OldBounds.PushBack(Map Elem->GetBB());96 OldBounds.PushBack(MapPrim->GetBB()); 97 97 98 Map Elem->Assign(m_OldStates[i]);98 MapPrim->Assign(m_OldStates[i]); 99 99 100 UpdateObjects.PushBack(Map Elem);100 UpdateObjects.PushBack(MapPrim); 101 101 } 102 102 -
cafu/trunk/CaWE/MapCommands/Morph.hpp
r292 r446 27 27 28 28 class MapDocumentT; 29 class Map ElementT;29 class MapPrimitiveT; 30 30 class MorphPrimT; 31 31 … … 48 48 MapDocumentT& m_MapDoc; 49 49 const ArrayT<MorphPrimT*> m_MorphPrims; 50 ArrayT<Map ElementT*>m_OldStates;50 ArrayT<MapPrimitiveT*> m_OldStates; 51 51 }; 52 52 -
cafu/trunk/CaWE/MorphPrim.cpp
r285 r446 33 33 #include "Math3D/Polygon.hpp" 34 34 35 #if defined(_WIN32) && defined(_MSC_VER)36 #if (_MSC_VER<1300)37 #define for if (false) ; else for38 #endif39 #endif40 41 35 42 36 MP_EdgeT::MP_EdgeT() … … 50 44 51 45 52 MorphPrimT::MorphPrimT(Map ElementT* MapElem)53 : m_Map Elem(MapElem),46 MorphPrimT::MorphPrimT(MapPrimitiveT* MapPrim) 47 : m_MapPrim(MapPrim), 54 48 m_Modified(false) 55 49 { 56 MapBrushT* MapBrush=dynamic_cast<MapBrushT*> (m_Map Elem);57 MapBezierPatchT* MapPatch=dynamic_cast<MapBezierPatchT*>(m_Map Elem);50 MapBrushT* MapBrush=dynamic_cast<MapBrushT*> (m_MapPrim); 51 MapBezierPatchT* MapPatch=dynamic_cast<MapBezierPatchT*>(m_MapPrim); 58 52 59 53 wxASSERT(MapBrush!=NULL || MapPatch!=NULL); // Assert they are not both NULL. … … 105 99 106 100 107 bool MorphPrimT::ApplyMorphToMap Elem()108 { 109 MapBrushT* MapBrush=dynamic_cast<MapBrushT*> (m_Map Elem);110 MapBezierPatchT* MapPatch=dynamic_cast<MapBezierPatchT*>(m_Map Elem);101 bool MorphPrimT::ApplyMorphToMapPrim() 102 { 103 MapBrushT* MapBrush=dynamic_cast<MapBrushT*> (m_MapPrim); 104 MapBezierPatchT* MapPatch=dynamic_cast<MapBezierPatchT*>(m_MapPrim); 111 105 112 106 wxASSERT(MapBrush!=NULL || MapPatch!=NULL); // Assert they are not both NULL. … … 388 382 m_Modified=true; 389 383 390 if (m_Map Elem->GetType()==&MapBezierPatchT::TypeInfo) UpdatePatch();391 if (m_Map Elem->GetType()== &MapBrushT::TypeInfo) UpdateBrushFromVertices();384 if (m_MapPrim->GetType()==&MapBezierPatchT::TypeInfo) UpdatePatch(); 385 if (m_MapPrim->GetType()== &MapBrushT::TypeInfo) UpdateBrushFromVertices(); 392 386 } 393 387 … … 395 389 void MorphPrimT::UpdateBrushFromVertices() 396 390 { 397 if (dynamic_cast<MapBrushT*>(m_Map Elem)==NULL) return;391 if (dynamic_cast<MapBrushT*>(m_MapPrim)==NULL) return; 398 392 399 393 const float Epsilon=0.1f; … … 525 519 void MorphPrimT::UpdatePatch() 526 520 { 527 MapBezierPatchT* MapPatch=(MapBezierPatchT*)m_Map Elem;521 MapBezierPatchT* MapPatch=(MapBezierPatchT*)m_MapPrim; 528 522 529 523 for (unsigned long y=0; y<MapPatch->GetHeight(); y++) -
cafu/trunk/CaWE/MorphPrim.hpp
r285 r446 29 29 class MapBezierPatchT; 30 30 class MapBrushT; 31 class Map ElementT;31 class MapPrimitiveT; 32 32 class Renderer2DT; 33 33 class Renderer3DT; … … 101 101 102 102 /// The constructor. 103 /// @param Map Elem 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 Map Elem 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 Map Elem object.106 MorphPrimT(Map ElementT* 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); 107 107 108 108 ~MorphPrimT(); 109 109 110 Map ElementT* 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; } 112 112 113 113 /// Updates the associated map element by applying the morphed geometry to it. 114 114 /// @returns if the update was successful. 115 bool ApplyMorphToMap Elem();115 bool ApplyMorphToMapPrim(); 116 116 117 117 /// Moves the selected handles by Delta. … … 135 135 /// After a change of (or in) the m_Vertices array, this method computes the convex hull over them 136 136 /// 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_Map Elem member is of type MapBrushT,137 /// This method should only be called if the m_MapPrim member is of type MapBrushT, 138 138 /// because it also modifies the m_Vertices array, which is not desired for the MapBezierPatchT type. 139 139 void UpdateBrushFromVertices(); … … 147 147 148 148 149 Map ElementT* m_MapElem; ///< The "attached" map brush / bezier patch.149 MapPrimitiveT* m_MapPrim; ///< The "attached" map brush / bezier patch. 150 150 bool m_Modified; ///< Whether the MorphPrimT contains any modifications to the "attached" map brush/bezier patch. 151 151 }; -
cafu/trunk/CaWE/ToolMorph.cpp
r444 r446 143 143 // For each brush or bezier patch in the documents selection, create a related instance here. 144 144 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 } 146 151 } 147 152 } … … 163 168 { 164 169 for (unsigned long MPNr=0; MPNr<m_MorphPrims.Size(); MPNr++) 165 if (m_MorphPrims[MPNr]->Get Elem()==Elem)170 if (m_MorphPrims[MPNr]->GetMapPrim()==Elem) 166 171 return MPNr; 167 172 … … 180 185 if (!m_MorphPrims[MPNr]->IsModified()) 181 186 { 182 UnmodifiedMapElems.PushBack(m_MorphPrims[MPNr]->Get Elem());187 UnmodifiedMapElems.PushBack(m_MorphPrims[MPNr]->GetMapPrim()); 183 188 184 189 delete m_MorphPrims[MPNr]; … … 208 213 209 214 210 void ToolMorphT::MorphPrims_Toggle Elem(MapElementT* Elem)215 void ToolMorphT::MorphPrims_TogglePrim(MapPrimitiveT* MapPrim) 211 216 { 212 217 // Only needed for observer message. 213 218 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); 217 222 218 223 if (MP_Index>=0) … … 244 249 } 245 250 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); 249 254 m_MorphPrims.PushBack(MorphPrim); 250 255 … … 457 462 } 458 463 459 if (dynamic_cast<MapBrushT*>(m_MorphPrims[0]->Get Elem())==NULL)464 if (dynamic_cast<MapBrushT*>(m_MorphPrims[0]->GetMapPrim())==NULL) 460 465 { 461 466 wxMessageBox("The morph tool can add new vertices only to brushes (not to Bezier patches).\n" … … 617 622 for (unsigned long HitNr=0; HitNr<HitElems.Size(); HitNr++) 618 623 { 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)) 620 627 { 621 628 if (!ME.ControlDown()) MorphPrims_CommitAndClear(); 622 MorphPrims_Toggle Elem(HitElems[HitNr]);629 MorphPrims_TogglePrim(HitPrim); 623 630 624 631 m_ToolMan.UpdateAllObservers(this, UPDATE_NOW); … … 885 892 if (HitElems.Size()>0) // Only consider the nearest hit, if any. 886 893 { 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)) 888 897 { 889 898 if (!ME.ControlDown()) MorphPrims_CommitAndClear(); 890 MorphPrims_Toggle Elem(HitElems[0].Object);899 MorphPrims_TogglePrim(HitPrim); 891 900 892 901 m_ToolMan.UpdateAllObservers(this, UPDATE_NOW); … … 1032 1041 for (unsigned long i=0; i<MapElements.Size(); i++) 1033 1042 { 1043 MapPrimitiveT* MapPrim=dynamic_cast<MapPrimitiveT*>(MapElements[i]); 1044 1045 if (!MapPrim) continue; 1046 1034 1047 for (unsigned long j=0; j<m_MorphPrims.Size(); j++) 1035 1048 { 1036 if (Map Elements[i]==m_MorphPrims[j]->GetElem())1049 if (MapPrim==m_MorphPrims[j]->GetMapPrim()) 1037 1050 { 1038 1051 // Remove this morph primitive from our list. … … 1057 1070 for (unsigned long i=0; i<MapElements.Size(); i++) 1058 1071 { 1072 MapPrimitiveT* MapPrim=dynamic_cast<MapPrimitiveT*>(MapElements[i]); 1073 1074 if (!MapPrim) continue; 1075 1059 1076 for (unsigned long j=0; j<m_MorphPrims.Size(); j++) 1060 1077 { 1061 if (Map Elements[i]==m_MorphPrims[j]->GetElem())1078 if (MapPrim==m_MorphPrims[j]->GetMapPrim()) 1062 1079 { 1063 1080 // Update the morph primitive of this map element, discarding all prior changes, if any. 1064 1081 delete m_MorphPrims[j]; 1065 m_MorphPrims[j]=new MorphPrimT(Map Elements[i]);1082 m_MorphPrims[j]=new MorphPrimT(MapPrim); 1066 1083 1067 1084 // Object has been found so we can safely break the inner loop and check the next object. … … 1082 1099 for (unsigned long i=0; i<MapElements.Size(); i++) 1083 1100 { 1101 MapPrimitiveT* MapPrim=dynamic_cast<MapPrimitiveT*>(MapElements[i]); 1102 1103 if (!MapPrim) continue; 1104 1084 1105 for (unsigned long j=0; j<m_MorphPrims.Size(); j++) 1085 1106 { 1086 if (Map Elements[i]==m_MorphPrims[j]->GetElem())1107 if (MapPrim==m_MorphPrims[j]->GetMapPrim()) 1087 1108 { 1088 1109 // Update the morph primitive of this map element, discarding all prior changes, if any. 1089 1110 delete m_MorphPrims[j]; 1090 m_MorphPrims[j]=new MorphPrimT(Map Elements[i]);1111 m_MorphPrims[j]=new MorphPrimT(MapPrim); 1091 1112 1092 1113 // Object has been found so we can safely break the inner loop and check the next object. -
cafu/trunk/CaWE/ToolMorph.hpp
r285 r446 117 117 int MorphPrims_Find(const MapElementT* Elem) const; ///< Returns the array index number of the MorphPrimT for the given Elem, -1 if there is none. 118 118 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_Toggle Elem(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. 120 120 void MoveSelectedHandles(const Vector3fT& Delta); ///< WARNING: This method *DESTROYS* all handle pointers into any of the m_MorphPrims!! 121 121 void NudgeSelectedHandles(const AxesInfoT& AxesInfo, const wxKeyEvent& KE);
