Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
- (IBAction)onBlackBackgroundPressed:(id)sender
{
    [[CFxNativeConnection GetNativeConnection] SetBackgroundColor:BLACK];
}

- (IBAction)onWhiteBackgroundPressed:(id)sender
{
    [[CFxNativeConnection GetNativeConnection] SetBackgroundColor:WHITE];
}

- (IBAction)onMagentaBackgroundPressed:(id)sender
{
    [[CFxNativeConnection GetNativeConnection] SetBackgroundColor:MAGENTA];
}

 

DWG Viewer - Switch between model and sheets

Status
titleOBJ-C
Status
colourYellow
titleC++

The DWG Viewer uses a native method -(void)AddSheetButtonsTo:(UIStackView*)sheets to get all available sheets of the drawing. All available sheets are stored as a UIButton inside a UIStackView. The button is linked with a command expression that is executed when tapped. The command _SHEET_CONTROL handles the layout switch.

 

File: ViewController.m

Code Block
languageobjective-c
-(void)viewDidAppear:(BOOL)animated
{
    ...
    [[CFxNativeConnection GetNativeConnection] AddSheetButtonsTo:m_StackSheets.firstObject];
}


File: CFxNativeConnection.mm

Code Block
languageobjective-c
-(void)AddSheetButtonsTo:(UIStackView*)sheets
{
    [CFxARESInstance runOnWorkingThread:^
    {
        std::map<int, CFxString> layouts;

        CFxDatabasePtr pDB = ACTIVE_DOCUMENT()->GetFxDatabase();
        if ( pDB.isNull() )
            return;

        OdDbDictionaryPtr layoutDictionary = pDB->getLayoutDictionaryId().openObject();
        OdDbDictionaryIteratorPtr iterator = layoutDictionary->newIterator();
        while( !iterator->done() )
        {
            OdDbLayoutPtr pLayout = iterator->object();
            layouts[ pLayout->getTabOrder() ] = pLayout->getLayoutName();
            iterator->next();
        }

        [CFxARESInstance runOnUiThread:^
        {
            [sheets setSpacing:10];
            for (auto layout : layouts)
            {
                UIButton* button = [UIButton buttonWithType:UIButtonTypeSystem];

                NSString* sheet = [NSString stringWithFormat:@"%@", [CFxNativeConnection nsStringFromWchar:layout.second.wide_str()]];
                [button setTitle:sheet forState:UIControlStateNormal];

                [button setContentEdgeInsets:UIEdgeInsetsMake(0, 12, 0, 12)];

                [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                CGFloat grayLevel = 2.0/3.0;
                [button setBackgroundColor:[UIColor colorWithRed:grayLevel green:grayLevel blue:grayLevel alpha:1]];

                [button addTarget:self action:@selector(OnSheetButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

                [sheets addArrangedSubview:button];
            }
            UIView* filler = [[UIView alloc] init];
            [sheets addArrangedSubview:filler];
        }];
    }];
}

 

File: CFxNativeConnection.mm

Code Block
languageobjective-c
-(IBAction)OnSheetButtonPressed:(UIButton*)button
{
    NSString* cmd = [NSString stringWithFormat:@"_SHEET_CONTROL\n_ACTIVATE\n%@\n", [button currentTitle]];
    [[CFxARESInstance instance] runCommand:cmd];
}