static void AutoGenerateBGroupNames (P3DPlantModel *PlantModel) { unsigned int BranchGroupIndex; P3DBranchModel *BranchModel; char NameBuffer[128]; PlantModel->GetPlantBase()->SetName("Plant"); BranchGroupIndex = 0; BranchModel = P3DPlantModel::GetBranchModelByIndex(PlantModel,BranchGroupIndex); while (BranchModel != 0) { snprintf(NameBuffer,sizeof(NameBuffer),"Branch%u",BranchGroupIndex + 1); NameBuffer[sizeof(NameBuffer) - 1] = 0; BranchModel->SetName(NameBuffer); BranchGroupIndex++; BranchModel = P3DPlantModel::GetBranchModelByIndex(PlantModel,BranchGroupIndex); } }
void P3DPlantModelTreeCtrl::OnAppendBranchNewClick (wxCommandEvent &event) { P3DBranchModel *ParentBranchModel; P3DBranchModel *ChildBranchModel; ParentBranchModel = ((P3DPlantModelTreeCtrlItemData*)(GetItemData(GetSelection())))->GetBranchModel(); ChildBranchModel = new P3DBranchModel(); ChildBranchModel->SetName (GenerateClonedBranchName (P3DApp::GetApp()->GetModel(),ParentBranchModel).c_str()); P3DStemModelTube *StemModel = P3DApp::GetApp()->CreateStemModelTube(); unsigned int Level = 0; for (wxTreeItemId ItemId = GetSelection(); ItemId != GetRootItem(); ItemId = GetItemParent(ItemId)) { Level++; } if (Level == 0) { StemModel->SetProfileResolution(P3DApp::GetApp()->GetModelPrefs().TubeCrossSectResolution[0]); } else if (Level == 1) { StemModel->SetProfileResolution(P3DApp::GetApp()->GetModelPrefs().TubeCrossSectResolution[1]); } else { StemModel->SetProfileResolution(P3DApp::GetApp()->GetModelPrefs().TubeCrossSectResolution[2]); } ChildBranchModel->SetStemModel(StemModel); if (GetSelection() == GetRootItem()) { ChildBranchModel->SetBranchingAlg(new P3DBranchingAlgBase()); } else { ChildBranchModel->SetBranchingAlg(P3DApp::GetApp()->CreateBranchingAlgStd()); } ChildBranchModel->SetMaterialInstance(P3DApp::GetApp()->CreateMatInstanceStd()); P3DApp::GetApp()->ExecEditCmd (new AppendBranchCommand(ParentBranchModel,ChildBranchModel,this)); }
void P3DPlantModelTreeCtrl::OnAppendBranchCopyClick (wxCommandEvent &event) { P3DListDialog SourceSelectionDialog(NULL,wxID_ANY,wxT("Select group to copy")); bool Done; P3DPlantModel *PlantModel; P3DBranchModel *BranchModel; unsigned int BranchIndex; PlantModel = P3DApp::GetApp()->GetModel(); BranchIndex = 0; BranchModel = P3DPlantModel::GetBranchModelByIndex(PlantModel,BranchIndex); while (BranchModel != 0) { SourceSelectionDialog.AddChoice(BranchModel->GetName()); BranchModel = P3DPlantModel::GetBranchModelByIndex(PlantModel,++BranchIndex); } SourceSelectionDialog.SetSelection(0); if (SourceSelectionDialog.ShowModal() == wxID_OK) { int SourceBranchIndex; SourceBranchIndex = SourceSelectionDialog.GetSelection(); if (SourceBranchIndex >= 0) { const P3DBranchModel *SourceBranchModel; P3DBranchModel *ParentBranchModel; P3DBranchModel *ChildBranchModel; P3DStemModelWings *WingsStemModel; const P3DBranchingAlg *SourceBranchingAlg; P3DStemModel *NewStemModel; P3DBranchingAlg *NewBranchingAlg; P3DVisRangeState *NewVisRange; float MinRange,MaxRange; SourceBranchModel = P3DPlantModel::GetBranchModelByIndex(PlantModel,SourceBranchIndex); ParentBranchModel = ((P3DPlantModelTreeCtrlItemData*)(GetItemData(GetSelection())))->GetBranchModel(); if (dynamic_cast<const P3DStemModelWings*>(SourceBranchModel->GetStemModel()) != 0) { if (ParentBranchModel->GetStemModel() == 0) /* trunk */ { ::wxMessageBox(wxT("\"Wings\" stem can be added to \"Tube\" stems only"), wxT("Error"), wxICON_ERROR | wxOK); return; } } ChildBranchModel = new P3DBranchModel(); ChildBranchModel->SetName (GenerateClonedBranchName (P3DApp::GetApp()->GetModel(),SourceBranchModel).c_str()); NewStemModel = SourceBranchModel->GetStemModel()->CreateCopy(); WingsStemModel = dynamic_cast<P3DStemModelWings*>(NewStemModel); if (WingsStemModel != 0) { WingsStemModel->SetParent((P3DStemModelTube*)ParentBranchModel->GetStemModel()); } ChildBranchModel->SetStemModel(NewStemModel); if ((dynamic_cast<const P3DBranchingAlgBase*>(SourceBranchModel->GetBranchingAlg())) != 0) { if (ParentBranchModel->GetStemModel() == 0) { NewBranchingAlg = SourceBranchModel->GetBranchingAlg()->CreateCopy(); } else { NewBranchingAlg = P3DApp::GetApp()->CreateBranchingAlgStd(); } } else { if (ParentBranchModel->GetStemModel() == 0) { NewBranchingAlg = new P3DBranchingAlgBase(); } else { NewBranchingAlg = SourceBranchModel->GetBranchingAlg()->CreateCopy(); } } ChildBranchModel->SetBranchingAlg(NewBranchingAlg); ChildBranchModel->SetMaterialInstance(SourceBranchModel->GetMaterialInstance()->CreateCopy()); NewVisRange = ChildBranchModel->GetVisRangeState(); NewVisRange->SetState(SourceBranchModel->GetVisRangeState()->IsEnabled()); SourceBranchModel->GetVisRangeState()->GetRange(&MinRange,&MaxRange); NewVisRange->SetRange(MinRange,MaxRange); P3DApp::GetApp()->ExecEditCmd (new AppendBranchCommand(ParentBranchModel,ChildBranchModel,this)); } } }