示例#1
0
                   P3DPlantModelTreeCtrl::P3DPlantModelTreeCtrl
                                      (wxWindow           *parent,
                                       P3DPlantModel      *PlantModel,
                                       P3DBranchPanel     *BranchPanel)
                   : wxTreeCtrl(parent,PLANT_TREE_CTRL_ID,wxDefaultPosition,
                                wxDefaultSize,wxTR_HAS_BUTTONS | wxRAISED_BORDER)
 {
  this->BranchPanel = BranchPanel;

  SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));

  P3DBranchModel  *PlantBase;

  PlantBase = PlantModel->GetPlantBase();

  wxTreeItemId RootId = AddRoot(MakeTreeItemLabel(PlantBase->GetName(),PlantBase));

  SetItemData(RootId,new P3DPlantModelTreeCtrlItemData(PlantBase));

  AppendChildrenRecursive(PlantBase,RootId);

  #if defined(__WXMSW__)
   {
    SetItemBold(RootId,true);
   }
  #endif
 }
示例#2
0
void               P3DPlantModelTreeCtrl::OnRenameStemClick
                                      (wxCommandEvent     &event)
 {
  wxTreeItemId     ItemId;
  P3DBranchModel  *BranchModel;
  wxString         NewName;
  bool             Done;

  ItemId = GetSelection();

  if (!ItemId.IsOk())
   {
    return;
   }

  BranchModel = ((P3DPlantModelTreeCtrlItemData*)(GetItemData(ItemId)))->GetBranchModel();

  Done = false;

  while (!Done)
   {
    Done    = true;
    NewName = ::wxGetTextFromUser(wxT("Enter new branch group name:"),
                                  wxT("Branch group name"),
                                  wxString(BranchModel->GetName(),wxConvUTF8));

    if (!NewName.IsEmpty())
     {
      P3DBranchModel  *TempBranchModel;

      TempBranchModel = P3DPlantModel::GetBranchModelByName(P3DApp::GetApp()->GetModel(),NewName.mb_str(wxConvUTF8));

      if (TempBranchModel == 0)
       {
        P3DApp::GetApp()->ExecEditCmd
         (new RenameStemCommand(BranchModel,NewName,this));
       }
      else
       {
        if (TempBranchModel != BranchModel)
         {
          ::wxMessageBox(wxT("Branch with this name already exists"),
                         wxT("Error"),
                         wxICON_ERROR | wxOK);

          Done = false;
         }
       }
     }
   }
 }
示例#3
0
void               P3DPlantModelTreeCtrl::UpdateLabel
                                      (wxTreeItemId        ItemId)
 {
  P3DBranchModel                      *BranchModel;
  wxTreeItemIdValue                    Cookie;

  BranchModel = ((P3DPlantModelTreeCtrlItemData*)(GetItemData(ItemId)))->GetBranchModel();

  SetItemText(ItemId,MakeTreeItemLabel(BranchModel->GetName(),BranchModel));

  wxTreeItemId ChildId = GetFirstChild(ItemId,Cookie);

  while (ChildId.IsOk())
   {
    UpdateLabel(ChildId);

    ChildId = GetNextChild(ItemId,Cookie);
   }
 }
示例#4
0
void               P3DPlantModelTreeCtrl::AppendChildrenRecursive
                                      (P3DBranchModel     *BranchModel,
                                       wxTreeItemId        BranchItemId)
 {
  unsigned int                         BranchIndex;
  P3DBranchModel                      *SubBranchModel;

  for (BranchIndex = 0;
       BranchIndex < BranchModel->GetSubBranchCount();
       BranchIndex++)
   {
    SubBranchModel = BranchModel->GetSubBranchModel(BranchIndex);

    wxTreeItemId ChildId = AppendItem(BranchItemId,MakeTreeItemLabel(SubBranchModel->GetName(),SubBranchModel));

    SetItemData(ChildId,new P3DPlantModelTreeCtrlItemData(SubBranchModel));

    AppendChildrenRecursive(SubBranchModel,ChildId);
   }
 }
示例#5
0
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));
     }
   }
 }