Exemplo n.º 1
0
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);
   }
 }
Exemplo n.º 2
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
 }
Exemplo n.º 3
0
void               P3DPlantModelTreeCtrl::OnHideShowStemClick
                                      (wxCommandEvent     &event)
 {
  P3DBranchModel                      *BranchModel;
  P3DMaterialInstanceSimple           *MaterialSimple;

  BranchModel = ((P3DPlantModelTreeCtrlItemData*)(GetItemData(GetSelection())))->GetBranchModel();
  MaterialSimple = dynamic_cast<P3DMaterialInstanceSimple*>(BranchModel->GetMaterialInstance());

  P3DApp::GetApp()->ExecEditCmd(new HideShowEditCommand(MaterialSimple));
 }
Exemplo n.º 4
0
void               P3DPlantModelTreeCtrl::OnSetStemModelWingsClick
                                      (wxCommandEvent     &event)
 {
  P3DBranchModel                      *BranchModel;
  P3DBranchModel                      *ParentBranchModel;
  const P3DStemModelTube              *ParentStemModel;
  P3DStemModel                        *StemModel;
  P3DBranchingAlg                     *BranchingAlg;
  wxTreeItemId                         ParentId;

  ParentId = GetItemParent(GetSelection());

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

  ParentBranchModel = ((P3DPlantModelTreeCtrlItemData*)(GetItemData(ParentId)))->GetBranchModel();
  ParentStemModel   = dynamic_cast<const P3DStemModelTube*>(ParentBranchModel->GetStemModel());

  if (ParentStemModel == 0)
   {
    return;
   }

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

  StemModel    = new P3DStemModelWings(ParentStemModel);
  BranchingAlg = new P3DBranchingAlgWings();

  unsigned int SubBranchIndex;
  wxTreeItemId ItemId;
  wxTreeItemId ParentItemId;

  SubBranchIndex = 0;
  ItemId         = GetSelection();
  ParentItemId   = GetItemParent(ItemId);

  while ((ItemId = GetPrevSibling(ItemId)).IsOk())
   {
    SubBranchIndex++;
   }

  P3DApp::GetApp()->ExecEditCmd
   (new ChangeStemModelCommand
         (ParentBranchModel,
          SubBranchIndex,
          BranchModel,
          StemModel,
          BranchingAlg,
          this,
          BranchPanel));
 }
Exemplo n.º 5
0
void               P3DPlantModel::Load(P3DInputStringStream
                                                          *SourceStream,
                                       P3DMaterialFactory *MaterialFactory)
 {
  P3DInputStringFmtStream                                  FmtStream(SourceStream);
  P3DFileVersion                                           Version;

  while (PlantBase->GetSubBranchCount() > 0)
   {
    PlantBase->RemoveSubBranch(PlantBase->GetSubBranchCount() - 1);
   }

  FmtStream.ReadFmtStringTagged("P3D","uu",&Version.Major,&Version.Minor);

  if ((Version.Major != P3D_VERSION_MAJOR) ||
      (Version.Minor  > P3D_VERSION_MINOR))
   {
    throw P3DExceptionGeneric("unsupported file format version");
   }

  if (Version.Minor < 7)
   {
    FmtStream.EnableEscapeChars(false);
   }

  FmtStream.ReadFmtStringTagged("BaseSeed","u",&BaseSeed);

  /*FIXME: not fully correct - we must work with FmtStream */
  if (!SourceStream->Eof())
   {
    if (Version.Minor < 3)
     {
      P3DBranchModel        *TrunkBranchModel;

      TrunkBranchModel = new P3DBranchModel();
      TrunkBranchModel->SetBranchingAlg(new P3DBranchingAlgBase());

      PlantBase->AppendSubBranch(TrunkBranchModel);

      TrunkBranchModel->Load(&FmtStream,MaterialFactory,0,&Version);
     }
    else
     {
      PlantBase->Load(&FmtStream,MaterialFactory,0,&Version);
     }

    if ((Version.Major == 0) && (Version.Minor < 4))
     {
      AutoGenerateBGroupNames(this);
     }
   }
 }
Exemplo n.º 6
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;
         }
       }
     }
   }
 }
Exemplo n.º 7
0
void               P3DPlantModelTreeCtrl::OnSetStemDummyModeClick
                                      (wxCommandEvent     &event)
 {
  wxTreeItemId                         ItemId;
  P3DBranchModel                      *BranchModel;

  ItemId = GetSelection();

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

  P3DApp::GetApp()->ExecEditCmd
   (new P3DBranchModelBoolParamEditCmd
         (BranchModel,
          event.IsChecked(),
          BranchModel->IsDummy(),
          &P3DBranchModel::SetDummy));
 }
Exemplo n.º 8
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);
   }
 }
Exemplo n.º 9
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);
   }
 }
Exemplo n.º 10
0
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));
 }
Exemplo n.º 11
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));
     }
   }
 }
Exemplo n.º 12
0
void               P3DPlantModelTreeCtrl::OnItemRightClick
                                      (wxTreeEvent        &event)
 {
  P3DBranchModel                      *BranchModel;
  P3DMaterialInstanceSimple           *MaterialSimple;

  if (event.GetItem() != GetSelection())
   {
    SelectItem(event.GetItem());
   }

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

  wxMenu                               PopupMenu;
  wxMenu                              *StemModelMenu;
  wxMenu                              *AppendBranchMenu;

  P3DStemModel *StemModel = BranchModel->GetStemModel();

  if (StemModel == 0)
   {
   }
  else
   {
    StemModelMenu = new wxMenu();
    StemModelMenu->Append(P3D_SET_STEM_MODEL_TUBE_ID,wxT("Tube"));
    StemModelMenu->Append(P3D_SET_STEM_MODEL_QUAD_ID,wxT("Quad"));
    StemModelMenu->Append(P3D_SET_STEM_MODEL_WINGS_ID,wxT("Wings"));

    if      (dynamic_cast<P3DStemModelTube*>(StemModel) != 0)
     {
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_TUBE_ID,false);
     }
    else if (dynamic_cast<P3DStemModelQuad*>(StemModel) != 0)
     {
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_QUAD_ID,false);
     }
    else if (dynamic_cast<P3DStemModelWings*>(StemModel) != 0)
     {
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_WINGS_ID,false);
     }

    const P3DPluginInfoVector &GMeshPlugins = P3DApp::GetApp()->GetGMeshPlugins();

    if (GMeshPlugins.size() > 0)
     {
      wxMenu      *GMeshPluginsMenu = new wxMenu();
      int          MenuItemId = wxID_GMESH_PLUGIN_FIRST;

      for (unsigned int Index = 0; Index < GMeshPlugins.size(); Index++)
       {
        GMeshPluginsMenu->Append(MenuItemId++,wxString(GMeshPlugins[Index].GetMenuName(),wxConvUTF8));
       }

      StemModelMenu->Append(P3D_SET_STEM_MODEL_GMESH_ID,wxT("G-Mesh"),GMeshPluginsMenu);
     }
    else
     {
      StemModelMenu->Append(P3D_SET_STEM_MODEL_GMESH_ID,wxT("G-Mesh"));
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_GMESH_ID,false);
     }

    if (BranchModel->GetSubBranchCount() > 0)
     {
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_QUAD_ID,false);
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_WINGS_ID,false);
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_GMESH_ID,false);
     }

    if (GetItemParent(GetSelection()) == GetRootItem())
     {
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_WINGS_ID,false);
     }
   }

  MaterialSimple = dynamic_cast<P3DMaterialInstanceSimple*>(BranchModel->GetMaterialInstance());

  AppendBranchMenu = new wxMenu();
  AppendBranchMenu->Append(PLANT_TREE_APPEND_BRANCH_NEW_ID,wxT("New branch"));
  AppendBranchMenu->Append(PLANT_TREE_APPEND_BRANCH_COPY_ID,wxT("Copy branch..."));

  PopupMenu.Append(PLANT_TREE_APPEND_BRANCH_ID,wxT("Append branch"),AppendBranchMenu);
  PopupMenu.Append(PLANT_TREE_REMOVE_STEM_ID,wxT("Delete stem"));

  if (GetItemParent(GetSelection()).IsOk())
   {
    PopupMenu.AppendSeparator();
    PopupMenu.Append(P3D_SET_STEM_MODEL_ID,wxT("Stem model"),StemModelMenu);

    wxMenuItem *DummyModeMenuItem = PopupMenu.AppendCheckItem(P3D_SET_STEM_DUMMY_MODE,wxT("Dummy"));

    DummyModeMenuItem->Check(BranchModel->IsDummy());

    PopupMenu.AppendSeparator();

    if (!BranchModel->IsDummy())
     {
      if (MaterialSimple->IsHidden())
       {
        PopupMenu.Append(PLANT_TREE_HIDESHOW_STEM_ID,wxT("Show"));
       }
      else
       {
        PopupMenu.Append(PLANT_TREE_HIDESHOW_STEM_ID,wxT("Hide"));
       }
     }
   }

  PopupMenu.Append(PLANT_TREE_RENAME_STEM_ID,wxT("Rename..."));

  if (GetRootItem() == GetSelection())
   {
    PopupMenu.Enable(PLANT_TREE_REMOVE_STEM_ID,false);
   }

  if (BranchModel->GetSubBranchCount() < P3DBranchModelSubBranchMaxCount)
   {
   }
  else
   {
    PopupMenu.Enable(PLANT_TREE_APPEND_BRANCH_ID,false);
   }

  if      (dynamic_cast<P3DStemModelQuad*>(StemModel) != 0)
   {
    PopupMenu.Enable(PLANT_TREE_APPEND_BRANCH_ID,false);
   }
  else if (dynamic_cast<P3DStemModelWings*>(StemModel) != 0)
   {
    PopupMenu.Enable(PLANT_TREE_APPEND_BRANCH_ID,false);
   }

  this->PopupMenu(&PopupMenu,event.GetPoint());
 }