iCAx开思网

标题: rhino犀牛的二次开发sdk程序代码 [打印本页]

作者: johnsunjiang    时间: 2006-3-9 14:48
标题: rhino犀牛的二次开发sdk程序代码
大家有空一起讨论讨论
以下代码是简单的添加新层的功能:
CRhinoCommand::result CCommandAddNewLayer::RunCommand(
        const CRhinoCommandContext& context
        )
  {
    CRhinoLayerTable& layer_table = context.m_doc.m_layer_table;
    ON_wString unused_name;
    layer_table.GetUnusedLayerName( unused_name );


    //提示输入层名
    CRhinoGetString gs;
    gs.SetCommandPrompt( L"Name of layer to add" );
    gs.SetDefaultString( unused_name );
    gs.AcceptNothing( TRUE );
    gs.GetString();
    if( gs.CommandResult() != CRhinoCommand::success )
      return gs.CommandResult();


    // 判断层名是否已输入
    ON_wString layer_name = gs.String();
    layer_name.TrimLeftAndRight();
    if( layer_name.IsEmpty() )
    {
      RhinoApp().Print( L"Layer name cannot be blank.\n" );
      return CRhinoCommand::cancel;
    }


    // 判断层名是否有效
    if( !RhinoIsValidName(layer_name) )
    {
      RhinoApp().Print( L"\"%s\" is not a valid layer name.\n", layer_name );
      return CRhinoCommand::cancel;
    }


    // 判断新加的层名是否已经存在
    int layer_index = layer_table.FindLayer( layer_name );
    if( layer_index >= 0 )
    {
      RhinoApp().Print( L"A layer with the name \"%s\" already exists.\n", layer_name );
      return CRhinoCommand::cancel;
    }


    // 创建新层
    ON_Layer layer;
    layer.SetLayerName( layer_name );


    // 添加层
    layer_index = layer_table.AddLayer( layer );
    if( layer_index < 0 )
    {
      RhinoApp().Print( L"Unable to add \"%s\" layer.\n", layer_name );
      return CRhinoCommand::failure;
    }


    return CRhinoCommand::success;
  }




欢迎光临 iCAx开思网 (https://www.icax.org/) Powered by Discuz! X3.3